DateFormat

Discussion in 'Java' started by Jun, Jan 6, 2004.

  1. Jun

    Jun Guest

    I tried to parse a date time string as following

    DateFormat df = DateFormat.getDateTimeInstance();
    dd = df.parse("Tue Jan 06 10:57:41 PST 2004");

    but failed.

    I even tried

    DateFormat df = DateFormat.getDateTimeInstance();
    Date d = new Date();
    dd = df.parse(d.toString());

    and also failed.

    What kind of format does it really take?

    thanks
    Jun, Jan 6, 2004
    #1
    1. Advertising

  2. Jun

    Chris Smith Guest

    Jun wrote:
    > I tried to parse a date time string as following
    >
    > DateFormat df = DateFormat.getDateTimeInstance();
    > dd = df.parse("Tue Jan 06 10:57:41 PST 2004");
    >
    > but failed.
    >
    > I even tried
    >
    > DateFormat df = DateFormat.getDateTimeInstance();
    > Date d = new Date();
    > dd = df.parse(d.toString());
    >
    > and also failed.
    >
    > What kind of format does it really take?


    The format expected by DateFormat instances returned by factory methods
    is entirely dependent on the locale. There is absolutely no guarantee
    that it will be a proper inverse of Date.toString, or that it will
    accept any other specific format. Because of that, I suggest that you
    don't use DateFormat instances from the static factory methods for
    parsing. That's especially true if you know the exact format of the
    input; in that case, use SimpleDateFormat to specify the format exactly.

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
    Chris Smith, Jan 6, 2004
    #2
    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. Phil
    Replies:
    0
    Views:
    589
  2. Grant Merwitz
    Replies:
    2
    Views:
    567
    Grant Merwitz
    Aug 18, 2005
  3. Sting
    Replies:
    2
    Views:
    346
    Thomas Weidenfeller
    Feb 19, 2004
  4. chirs

    DateFormat parse() method

    chirs, Apr 5, 2004, in forum: Java
    Replies:
    5
    Views:
    85,737
    asimali2002
    Mar 6, 2007
  5. KAR120C
    Replies:
    5
    Views:
    550
    Hendrik Maryns
    Jan 22, 2006
Loading...

Share This Page