aspose file tools
The moose likes Beginning Java and the fly likes Date Format Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 24054
    
  13

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Date Format
 
Similar Threads
Code review required for converting dateformat
Number Conversion to German Format!!
user-defined date format in XML schema
conversion from Date ojbect to Date object
Date formats