• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Date Format

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic