Getting an arbitary date the *RIGHT* way

A

Aryeh M. Friedman

After searching the web and the jdk 1.6 docs I am really confused
about how to get the date value of a arbitary mm/dd/yy... all the
stuff on the web says to use java.util.Date but the javadocs for it in
1.6 list almost every useful method (for setting/getting it with
anything except a timer count from the beginning of the UNIX epoch)
are Deprecated... but no one so far has suggested an alternative to
this?!??!!?
 
A

Andreas Leitgeb

Aryeh M. Friedman said:
After searching the web and the jdk 1.6 docs I am really confused
about how to get the date value of a arbitary mm/dd/yy... all the
stuff on the web says to use java.util.Date but the javadocs for it in
1.6 list almost every useful method (for setting/getting it with
anything except a timer count from the beginning of the UNIX epoch)
are Deprecated... but no one so far has suggested an alternative to
this?!??!!?

see java.util.Calendar
and java.util.GregorianCalendar

It most definitely is being suggested every once in a while here,
and quite surely also in lots of other places.
 
N

Nigel Wade

Aryeh said:
After searching the web and the jdk 1.6 docs I am really confused
about how to get the date value of a arbitary mm/dd/yy... all the
stuff on the web says to use java.util.Date but the javadocs for it in
1.6 list almost every useful method (for setting/getting it with
anything except a timer count from the beginning of the UNIX epoch)
are Deprecated... but no one so far has suggested an alternative to
this?!??!!?

Use a Calendar, the only concrete implementation of which is GregorianCalendar.

Calendar cal = new GregorianCalendar(year,month,day);

Date didn't deal with timezones, DST etc. so it only works in UTC. I presume
that many of the methods are deprecated because the class doesn't deal with
timezone, DST and those methods lead to incorrect results when used without due
care in other timezones. Calendar handles these issues properly, but in return
for that it is a huge and cumbersome class and exceedingly confusing to the
uninitiated (for the initiated it is merely confusing). But it works when you
get it right.
 
L

Lew

Uhhh ...

Andreas said:
see java.util.Calendar
and java.util.GregorianCalendar

It most definitely is being suggested every once in a while here,
and quite surely also in lots of other places.

Plus java.text.DateFormat and SimpleDateFormat.
<http://java.sun.com/javase/6/docs/api/java/text/DateFormat.html>

In particular, you seem to want
<http://java.sun.com/javase/6/docs/api/java/text/DateFormat.html#parse(java.lang.String)>

or a related method.

And stay tuned for JSR 310!
<http://today.java.net/pub/a/today/2008/09/18/jsr-310-new-java-date-time-api.html>
 
B

blue indigo

Indeed didn't we have a flamewar about it recently?
Plus java.text.DateFormat and SimpleDateFormat.
<http://java.sun.com/javase/6/docs/api/java/text/DateFormat.html>

In particular, you seem to want
<http://java.sun.com/javase/6/docs/api/java/text/DateFormat.html
#parse(java.lang.String)>

or a related method.

And stay tuned for JSR 310!
<http://today.java.net/pub/a/today/2008/09/18/jsr-310-new-java-
date-time-api.html>

Yes indeed. Date 1.0 was pants, and Date 2.0 made a mess of Calendar and
didn't add intervals. The only downside, both Date 2.0 and JSR 310 show
signs of second-system effect.
 
R

Roedy Green

After searching the web and the jdk 1.6 docs I am really confused
about how to get the date value of a arbitary mm/dd/yy... all the
stuff on the web says to use java.util.Date but the javadocs for it in
1.6 list almost every useful method (for setting/getting it with
anything except a timer count from the beginning of the UNIX epoch)
are Deprecated... but no one so far has suggested an alternative to
this?!??!!?

Date is almost gone, like a Cheshire cat.

see GregorianCalendar.

See http://mindprod.com/jgloss/calendar.html
http://mindprod.com/jgloss/date.html
--
Roedy Green Canadian Mind Products
http://mindprod.com

We are almost certainly going to miss our [global warming] deadline.
We cannot get the 10 lost years back, and by the time a new global agreement to
replace the Kyoto accord is negotiated and put into effect, there will probably
not be enough time left to stop the warming short of the point where we must not
go. ~ Gwynne Dyer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top