JodaTimeライブラリを使用して現地時間を取得するのに問題があります。これが私がやろうとしていることの簡単な例です。
package simple;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.LocalDateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
public class TestJodaLocalTime {
public static void main(String[] args) {
//time in UTC standard
DateTime processingDate = DateTime.now();
//local time
LocalDateTime localDateTime = processingDate.
withZone(DateTimeZone.getDefault()).toLocalDateTime();
DateTimeFormatter fmtDate = DateTimeFormat.forPattern("dd/MM/yyyy");
DateTimeFormatter fmtHour = DateTimeFormat.forPattern("HH:mm:ss");
System.out.println("Date: " + fmtDate.print(processingDate));
System.out.println("Time: " + fmtHour.withZone(DateTimeZone.UTC).
print(processingDate));
System.out.println("Local date: " + fmtDate.print(localDateTime));
System.out.println("Local time: " + fmtHour.print(localDateTime));
}
}
現地時間を印刷するときに、アプリケーションが実行されているタイムゾーンの時刻を取得することを期待していましたが、UTCDateTimeと同じ時刻を取得しました。
Date: 06/12/2012
Time: 12:55:49
Local date: 06/12/2012
Local time: 12:55:49
私はここで何を逃しましたか?