SimpleDateformat: 12 hour versus 24 hour

Discussion in 'Java' started by techshiv@gmail.com, Jun 1, 2007.

  1. Guest

    Hello,

    I have a date in the form of a string "5/31/2007 4:30:03 PM"

    And I convert this string to date and save it. This is what I do:

    SimpleDateFormat sdf=new SimpleDateFormat("MM/dd/yyyy kk:mm:ss");
    dtStamp=sdf.parse("5/31/2007 4:30:03 PM");

    and I am getting dtStamp as
    Thu May 31 04:30:03 EDT 2007

    I want time as 16:30,
    which I am not able to get irrespective of the format I use.

    Please let me know where I am going wrong. Thanks.

    Shiv
     
    , Jun 1, 2007
    #1
    1. Advertising

  2. Guest

    ok.. This worked

    SimpleDateFormat sdf=new SimpleDateFormat("MM/dd/yyyy hh:mm:ss aa");

    Shiv
     
    , Jun 1, 2007
    #2
    1. Advertising

  3. Hal Rosser Guest

    <> wrote in message
    news:...
    > ok.. This worked
    >
    > SimpleDateFormat sdf=new SimpleDateFormat("MM/dd/yyyy hh:mm:ss aa");
    >
    > Shiv
    >

    You could shorten it to
    SimpleDateFormat sdf=new SimpleDateFormat("M/d/y h:m:s a");
     
    Hal Rosser, Jun 1, 2007
    #3
    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. Matthew Louden
    Replies:
    1
    Views:
    7,021
    Scott M.
    Oct 11, 2003
  2. Russ

    script versus code versus ?

    Russ, Jun 10, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,524
  3. ssylee
    Replies:
    4
    Views:
    523
    Thad Smith
    Jan 1, 2008
  4. Paul Butcher
    Replies:
    12
    Views:
    756
    Gary Wright
    Nov 28, 2007
  5. Chris Gunnels
    Replies:
    4
    Views:
    170
    Robert Klemme
    Sep 16, 2010
Loading...

Share This Page