aspose file tools*
The moose likes Beginning Java and the fly likes Date Format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Date Format" Watch "Date Format" New topic
Author

Date Format

Eric Martin
Greenhorn

Joined: Jul 15, 2005
Posts: 22
Hello, I need to create a Date in a certain format and leave it as a Date object. How do I do this? I have looked at SimpleDateFormat, but all of its returns seem to be of type String.

TIA
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

A Date object represents the actual date -- i.e., the time in UTC. It's only in rendering the Date as a String that the concept of a format is introduced.

Beginners often make the same mistake with floating-point numbers. A float or double has some arbitrary number of decimal places -- i.e., 3.99999999654. It's only in rendering it as text that we choose to limit ourselves to two decimal places and get 4.00 .


[Jess in Action][AskingGoodQuestions]
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by Eric Martin:
Hello, I need to create a Date in a certain format and leave it as a Date object. How do I do this? I have looked at SimpleDateFormat, but all of its returns seem to be of type String.

TIA


Do you have the String that you need to use to create a Date object? Or similarly, do you have a Date object that you need to output as a String? As EFH mentions above, these are the only situations where the format has any meaning. (Internally, the Date class has its own representation of the date and time, which probably doesn't include a String.) To convert a String into a Date, use DateFormat.parse(). To convert a Date into a String, use DateFormat.format(). Notice that SimpleDateFormat extends DateFormat. This means that the documentation for SimpleDateFormat only contains information for the methods it overrides or adds. You should also look at the docs for the DateFormat class in order to see any methods that SimpleDateFormat inherits.

Layne
[ July 30, 2005: Message edited by: Layne Lund ]

Java API Documentation
The Java Tutorial
 
wood burning stoves
 
subject: Date Format