How do I get Java to parse and format a date/time with the same time zone? I keep getting the local timezone
Posted
by
fishtoprecords
on Stack Overflow
See other posts from Stack Overflow
or by fishtoprecords
Published on 2010-12-29T04:45:44Z
Indexed on
2010/12/29
4:53 UTC
Read the original article
Hit count: 247
My application keeps all Java Date's in UTC. Parsing them is easy, but when I print them out, the display shows the computer's local time zone, and I want to show it as UTC.
Example code:
String sample = "271210 200157 UTC";
SimpleDateFormat dfmt = new SimpleDateFormat("ddMMyy HHmmss Z");
Date result = dfmt.parse(sample);
System.out.printf("%tc\n", result);
the result is Mon Dec 27 15:01:57 EST 2010
What I want is Mon Dec 27 20:01:57 UTC 2010
Clearly I have to set some Locale and TimeZone values, but I don't see where to put them. Thanks Pat
© Stack Overflow or respective owner