• 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

Dates (using them, not getting them)

 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anybody recommend a good resource for learning about Java Dates?

I don't completely understand the relationship between GregorianCalendars and Dates and Locales. I have read the API and checked a couple books and I'm still fuzzy. It seems more complicated than it needs to be.

Has anybody here read a clear explaination of how to use Dates maybe with some best practices mixed in?
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are some articles in JavaWorld that talks about Dates,Times and Calendars that might interest you:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-dates.html
http://www.javaworld.com/javaworld/jw-03-2001/jw-0330-time.html
http://www.javaworld.com/javaworld/jw-12-1998/jw-12-internationalize.html
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's my approach to dates:

1). java.util.Date works well for storing a date value. This is about all it is good for. Fortunately, storing Dates is a commmon thing, so I use it a lot.

2). Use java.util.Calendar for date manipulations (adding time to dates, etc.)

3). Use milliseconds for calculating differences between dates. (Obtainable from a date.getTime(), or from a calendaer as calendar.getTime().getTime());

4). Use java.text.SimpleDateFormat for formatting dates to print -- unless you have to worry about locales. Then use the DateFormatter.getXXXInstance methods to get the locale-specific formats.

5). Unless you have to, don't worry about locales. But do use java.util.Calendar.getInstance() to get a locale-specific instance instead of using a GregorianCalendar directly. (In most cases it will return a GregorianCalendar anyway....)
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

Best way use Calendar class it contains, all the facilities, like DAY,MONTH, YEAR, DAY_OF_MONTH etc.

Thanx.
 
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Only the first of those links if any use. The second links to java.sql.Date which is not a general purpose class. The third shows the use of a Calendar object, and now that LocalDate is available, you shou‍ld no longer use Calendar or java.util.Date.
 
Hold that thought. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic