Getting an arbitary date the *RIGHT* way

Discussion in 'Java' started by Aryeh M. Friedman, Jan 21, 2009.

  1. 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?!??!!?
     
    Aryeh M. Friedman, Jan 21, 2009
    #1
    1. Advertising

  2. Aryeh M. Friedman <> wrote:
    > 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.
     
    Andreas Leitgeb, Jan 21, 2009
    #2
    1. Advertising

  3. Aryeh M. Friedman

    Nigel Wade Guest

    Aryeh M. Friedman wrote:

    > 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.

    --
    Nigel Wade
     
    Nigel Wade, Jan 21, 2009
    #3
  4. Aryeh M. Friedman

    Lew Guest

    Aryeh M. Friedman wrote:
    >> 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


    Uhhh ...

    >> 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?!??!!?


    Andreas Leitgeb wrote:
    > 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>


    --
    Lew
     
    Lew, Jan 22, 2009
    #4
  5. Lew <> wrote:
    > And stay tuned for JSR 310!
    ><http://today.java.net/pub/a/today/2008/09/18/jsr-310-new-java-date-time-api.html>


    Wow! I'm especially looking forward to Partial and Period.
     
    Andreas Leitgeb, Jan 22, 2009
    #5
  6. Aryeh M. Friedman

    blue indigo Guest

    On Wed, 5622 Sep 1993 21:31:54 -0500, Lew wrote:

    > Andreas Leitgeb wrote:
    >> 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.


    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.

    --
    blue indigo
    UA Telecom since 1987
     
    blue indigo, Jan 22, 2009
    #6
  7. Aryeh M. Friedman

    Roedy Green Guest

    On Wed, 21 Jan 2009 01:07:38 -0800 (PST), "Aryeh M. Friedman"
    <> wrote, quoted or indirectly quoted someone
    who 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?!??!!?


    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
     
    Roedy Green, Jan 23, 2009
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    1
    Views:
    621
    Matthew Speed
    Nov 8, 2003
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,304
    Michael Borgwardt
    May 30, 2004
  3. John Smith

    Arbitary VTABLE/Python

    John Smith, Apr 15, 2004, in forum: Python
    Replies:
    2
    Views:
    471
    Your name
    May 4, 2004
  4. George Vlahakis

    Receiving arbitary 2-dimensional tables in a WebService method

    George Vlahakis, Jun 27, 2006, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    122
  5. Aryeh M. Frierdman

    Freezing an arbitary object

    Aryeh M. Frierdman, Jul 6, 2003, in forum: Ruby
    Replies:
    8
    Views:
    131
    Robert Klemme
    Jul 7, 2003
Loading...

Share This Page