• Post Reply Bookmark Topic Watch Topic
  • New Topic

up to Date() ?  RSS feed

 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


java.util.Date appears to have been deprecated, and, the weird starting off of months from zero (0) rather than from one (1), is a turn-off in terms of code readability, imho.
It's been suggested to use other libraries, whilst Oracle are planning to release a design as proposed with Java SE 7.

How do you code dates in the meantime? Do you find issues and provide workarounds for dealing with timezone differences, and, DST?

Further reading
1. Joda.org - open source design for multiple calendar systems that is advertised to be ISO 8601 compliant, available at http://joda-time.sourceforge.net.
2. JSR 310 - JSR 310: Date and Time API - http://jcp.org/en/jsr/detail?id=310 - recommendation to review DateTime structures in Java.
3. java.util.GregorianCalendar class see Java Platform Standard Ed. 6 API - http://download.oracle.com/javase/6/docs/api.
4. Daylight Saving Time (DST) - http://en.wikipedia.org/wiki/Daylight_saving_time.


I've also note the following output:
Fri Apr 15 23:02:34 CEST 2011
Thu Jan 15 00:00:00 CET 3880

What is CEST 2011, and, CET 3880? Is it a bug that 3880 is the output instead of '1980'?


 
Paul Clapham
Sheriff
Posts: 22509
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, no, if you have a closer look at the documentation you'll see that java.util.Date hasn't been deprecated. Only most of its methods and constructors have. Likewise if you have another look for the documentation for the (deprecated) constructor you used there, you'll see where the extra 1900 came from.

There's no need for "workarounds" if you're dealing with time zones and daylight saving time, either. The java.util.Calendar class (and GregorianCalendar) do a perfectly good job of that. It mentions that in the first paragraph of the Date documentation. Admittedly it's clunky and full of premature optimizations (like numbering months starting from zero) which produced a large crop of subtle bugs, and a 21st-century version is long overdue, but it still does its job perfectly well.
 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Likewise if you have another look for the documentation for the (deprecated) constructor you used there, you'll see where the extra 1900 came from.


It says:
Date

public Date()
Allocates a Date object and initializes it so that it represents the time at which it was allocated, measured to the nearest millisecond.

I'm still in the dark...
 
mike ryan
Ranch Hand
Posts: 210
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jon,

public Date(int year,
int month,
int date)

Deprecated. As of JDK version 1.1, replaced by Calendar.set(year + 1900, month, date) or GregorianCalendar(year + 1900, month, date).

Allocates a Date object and initializes it so that it represents midnight, local time, at the beginning of the day specified by the year, month, and date arguments.

Parameters:
year - the year minus 1900.
month - the month between 0-11.
date - the day of the month between 1-31.
See Also:
Calendar




this is what it says in the documentation, maybe this helps you.
 
Paul Clapham
Sheriff
Posts: 22509
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe "CEST" is "Central European Standard Time" or something like that. Likewise "CET". Based on the information you posted it does appear to me that you are in that time zone.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CEST is Central European Summer Time (UTC + 2), CET is Central European Time (UTC + 1).

We use CET in the winter, CEST in the summer.
 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:I believe "CEST" is "Central European Standard Time" or something like that. Likewise "CET". Based on the information you posted it does appear to me that you are in that time zone.


Yes but I was wondering why one line reads 'CEST' and and another reads 'CET', it's inconsistent, and, looks like witchcraft to me :)
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jon Camilleri wrote:Yes but I was wondering why one line reads 'CEST' and and another reads 'CET', it's inconsistent, and, looks like witchcraft to me :)

There's a logical explanation for that: on 15 April summertime (CEST) is used in Europe, and on 15 January wintertime (CET) is used.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!