GregorianCalendar Class in Java

Ahh, the joys of the Java Date/Time API …

What you want (aside from a better API, such as Joda Time) is a DateFormat. It can print dates in a time zone you specify. You don’t need Calendar for that.

dateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Bangkok"));
dateFormat.format(new Date());

Calendar is for time manipulations and calculations. For example “set the time to 10 AM”. Then it needs the timezone.

When you are done with these calculations, then you can get the result by calling calendar.getTime() which returns a Date.

A Date is essentially a universal timestamp (in milliseconds since 1970, with no timezone information attached or relevant). If you call toString on a Date it will just print something in your default timezone. For more control, use DateFormat.

Leave a Comment