Forums Register Login

Date Format

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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 .
+Pie Number of slices to send: Send
 

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 ]
Ever since I found this suit I've felt strange new needs. And a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 995 times.
Similar Threads
Number Conversion to German Format!!
user-defined date format in XML schema
Code review required for converting dateformat
Date formats
conversion from Date ojbect to Date object
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 09:34:21.