コード例を次に示します。サーバーのデフォルトのタイムゾーンをニューヨーク時間に明示的に設定していますが、Jon Lin のヒントに従って、自分のサーバーのデフォルトのタイムゾーンを特定することをお勧めします。たとえば、NY にいて、SF でホストされているサーバーを使用し、太平洋時間を使用している場合、どのゾーンでも予想される時間とは 3 時間の差が生じる可能性があります。
public void testTodayInIndia() {
// For demonstration, make my system act as though it's in New York
TimeZone.setDefault(TimeZone.getTimeZone("America/New_York"));
long oneDay = 86400000;
long fourYears = (365 * 4 + 1) * oneDay;
// Calculate 42 years after 1/1/1970 UTC
Date now = new Date(fourYears * 10 + oneDay * 365 * 2 + 1);
TimeZone calcutta = TimeZone.getTimeZone("Asia/Kolkata");
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// Since unspecified, this output will show the date and time in New York
assertEquals("2011-12-31 19:00:00", formatter.format(now));
// After setting the formatter's time zone, output reflects the same instant in Calcutta.
formatter.setTimeZone(calcutta);
assertEquals("2012-01-01 05:30:00", formatter.format(now));
}