timestamptz
データは、取得時に自動的にJavaのデフォルトのタイムゾーンに変換されます。
java.util.TimeZone.setDefault(java.util.TimeZone)
でこのデフォルト値を変更できます。それはかなり侵襲的であり、全体JVM用のタイムゾーンを設定しているので、私は特定の時間帯にタイムスタンプをフォーマットする方法を紹介します
:
java.sql.ResultSet rs = stmt.executeQuery();
rs.next();
// fetch the first result column as java.sql.Timestamp object
java.sql.Timestamp d = rs.getObject(1, java.sql.Timestamp.class);
// create a calendar with the appropriate time zone
java.util.Calendar cal = java.util.Calendar.getInstance(
java.util.TimeZone.getTimeZone("Asia/Kolkata"));
// create a DateFormat with the appropriate format and locale
java.text.DateFormat df = java.text.DateFormat.getDateTimeInstance(
java.text.DateFormat.MEDIUM,
java.text.DateFormat.MEDIUM,
java.util.Locale.ENGLISH);
// tell the DateFormat to use the calendar with the right time zone
df.setCalendar(cal);
// output will be in the chosen time zone
System.out.println("timestamp = " + df.format(d));
TimeZone.setDefault'はないかもしれない '使い方あなたのアプリケーションの他の部分を壊す可能性があります。 –
これらの列はクライアントシステムのタイムゾーン*になるように質問され、その設定方法は不思議です。しかし、データを特定の時間帯に変換する方法についての情報を追加できます。 –