This is because getRawOffset() returns 0 - it does this for me and for "ET", but in fact TimeZone.getTimeZone("ET") basically returns GMT. I suspect that is not what you had in mind.
Olsonβs best time zone name for North Carolina is America / New York, I think.
Note that you should not just add the raw timezone offset to UTC - you should instead set the formatting timezone. The Date value really does not know about the time zone ... it is always only milliseconds since January 1, 1970 UTC.
So you can use:
import java.text .; import java.util .;
Date date = new Date(); DateFormat format = new SimpleDateFormat("dd/MM/yy h:mm a zzz"); format.setTimeZone(TimeZone.getTimeZone("America/New_York")); System.out.println("Eastern: " + format.format(date)); format.setTimeZone(TimeZone.getTimeZone("Etc/UTC")); System.out.println("UTC: " + format.format(date));
Output:
Eastern: 11/05/11 11:30 AM EDT UTC: 11/05/11 3:30 PM UTC
I also recommend that you learn Joda Time instead of the built-in libraries - this is a much better API.
source share