How do I get Java to parse and format a date/time with the same time zone? I keep getting the local timezone
- by fishtoprecords
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