The Date
class is intended to reflect coordinated universal time (UTC), so it does not reflect timezone you use in GregorianCalendar
. Also by default SimpleDateFormat
uses system default timezone and if you want to override it you should do it explicitly:
DateFormat format = new SimpleDateFormat("yyyy.MM.dd G 'at' HH:mm:ss z");
TimeZone la = TimeZone.getTimeZone("America/Los_Angeles");
format.setTimeZone(la);
Another option is to switch to Joda Time library:
DateTimeZone la = DateTimeZone.forTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
DateTimeFormat.forPattern(dateTimeFormat).withZone(la).print(System.currentTimeMillis());