Results 1 to 2 of 2
  1. #1
    plasma is offline Member
    Join Date
    Dec 2009
    Rep Power

    Default Convert String to Time format

    Hi there. I am new to java and am currently facing a problem with converting a string to time format. Here is my code:

    String str = "09:00:00 EST" ;
    DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss z");
    try {
    Date df = dateFormat.parse(str);
    } catch (Exception e) {

    09:00:00 EST
    Thu Jan 01 19:30:00 IST 1970

    I am confused as to how the wrong time is got in the output. Please help me out. Thanks in advance.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Rep Power


    The time is not wrong. It is being output in the local timezone and the "toString" format, as outlined in the API docs. If you want to output the time in a different format and timezone, then you need to set the timezone on the SimpleDateFormat object and output the Date string using SimpleDateFormat and its format method.

Similar Threads

  1. How Convert a Byte array to a image format
    By perlWhite in forum New To Java
    Replies: 2
    Last Post: 08-23-2009, 08:11 PM
  2. how to convert SWING GUI into exe format
    By santhosh_el in forum AWT / Swing
    Replies: 7
    Last Post: 04-04-2009, 12:36 PM
  3. how to convert one format to another format
    By mahipal_reddy621 in forum New To Java
    Replies: 1
    Last Post: 12-02-2008, 10:21 AM
  4. validate time input format
    By Alairmon in forum New To Java
    Replies: 2
    Last Post: 11-04-2008, 07:39 AM
  5. how to convert date format
    By saran123 in forum New To Java
    Replies: 5
    Last Post: 10-16-2008, 06:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts