Results 1 to 2 of 2
Thread: Convert String to Time format
- 12-16-2009, 07:20 AM #1
Member
- Join Date
- Dec 2009
- Posts
- 1
- Rep Power
- 0
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");
System.out.println(str);
try {
Date df = dateFormat.parse(str);
System.out.println(df);
} catch (Exception e) {
System.out.println(e.getMessage)
}
Output:
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.
- 12-16-2009, 08:58 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
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
-
How Convert a Byte array to a image format
By perlWhite in forum New To JavaReplies: 2Last Post: 08-23-2009, 08:11 PM -
how to convert SWING GUI into exe format
By santhosh_el in forum AWT / SwingReplies: 7Last Post: 04-04-2009, 12:36 PM -
how to convert one format to another format
By mahipal_reddy621 in forum New To JavaReplies: 1Last Post: 12-02-2008, 10:21 AM -
validate time input format
By Alairmon in forum New To JavaReplies: 2Last Post: 11-04-2008, 07:39 AM -
how to convert date format
By saran123 in forum New To JavaReplies: 5Last Post: 10-16-2008, 06:10 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks