質問

私はCalendarオブジェクト[localDate]はEST:言月6日15:34...このタイムゾーンをGMT+5:30...今の Calendar.HOUR_OF_DAY を返します2...あるいは..以来、15:34+5時GMTそ+5:30のタイムゾーン..こだわりを意味..26:04る2 7

ただし、当日システムとして月6...や localDate.getTime() まだ返月6..とっても印刷のlocalDate..このタイムゾーンとして+5:30頃の間は、その日その他のものは現地時間..[i.e月6]

私は単に理解できないのはなぜなので---

編集::

ということで私を変える必要はありませんの日付のタイムゾーン..変更の日付表示に適したインフルエンザの予防接種は、これをベースに制御を行っています。タイムゾーンがセットされています。

正しい解決策はありません

他のヒント

localDate.getTime() 返品a java.util.Date これは、固定点からの生の時間の量です。タイムゾーンは、時点の人間の読み取り可能な表現にのみ影響します。

15:34 Nov 6th UTC - 502:04 Nov 7th UTC + 5:30

どちらも絶対時間でまったく同じポイントです。同じ瞬間を説明する2つの異なる人間の方法です。

したがって、カレンダーのタイムゾーンを変更することは、によって返される値に影響を与えません getTime()

Date 物がないのタイムゾーンa Date オブジェクトが表す"絶対"する。ときに印刷 Date オブジェクト(暗黙的または明示的に呼び出し toString() めくりと操作上の違いがござい:

Date date = ...;
System.out.println(date);

そのフォントをデフォルトのフォーマットの日付現地時間はタイムゾーンの仕事に関して皆さんの Date オブジェクトから Calendar 設定した異なるtimezone.

表示したい場合には、 Date 異なるタイムゾーンを使用 DateFormat オブジェクトのタイムゾーンを表示するかどうかのお日にそのオブジェクト:

Date date = ...;

DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
df.setTimeZone(TimeZone.getTimeZone("UTC"));  // For example, UTC

// Prints 'date' in UTC
System.out.println(df.format(date));

質問は明確ではありません

あなたの質問は混乱しています。

タイムゾーンの意味について混乱する可能性があります。 JesperとAffeの正解が言ったように、タイムゾーンのシフトは宇宙のタイムラインのポイントを変えません。ニューヨークのボブがレイキャビクアイスランドのスーザンを呼ぶとします。アイスランドは、一年中UTCをタイムゾーンとして使用しています。ボブとスーザンは、同時にお互いに話し合っています。しかし、ボブが彼の壁の時計を見ると、彼はスーザンの壁の時計よりも5時間早く表示される時間を見ます。ニューヨークは、UTC(-5:00)に次いで5時間のオフセットがあります。

質問のもう1つの問題:5:00タイムゾーンオフセットと5:30のオフセットについても話します。どちらですか?または、GMT/UTCと同様に2つのタイムゾーンを念頭に置いていますか?

ジョーダタイム

ソースコードの例を少し紹介することで刺します。

ジョーダタイム ライブラリは、日付の作業を簡単にします。

// © 2013 Basil Bourque. This source code may be used freely forever by anyone taking full responsibility for doing so.

// Use time zone names rather than explicit number of hours offset is generally a good thing.
// Affords Joda-Time an opportunity to make adjustments such as Daylight Saving Time (DST).

// Question asked:
// (1) Start with a US east coast time (Standard offset of -5:00) of November 6, 2013 15:34.
// (2) Move that datetime to UTC (GMT) time zone (no offset).
// (3) Move that datetime to Kolkata (formerly known as Calcutta) India time zone (Standard offset of +05:30).

// Joda-Time has deprecated use of 3-letter time zone codes because of their inconsistency. Use other identifier for zone.
// Time Zone list: http://joda-time.sourceforge.net/timezones.html  (Possibly out-dated, read note on that page)
org.joda.time.DateTimeZone newyorkTimeZone = org.joda.time.DateTimeZone.forID( "America/New_York" );
org.joda.time.DateTimeZone kolkataTimeZone = org.joda.time.DateTimeZone.forID( "Asia/Kolkata" );

// Question calls for: EST Nov 6, 15:34 (Standard offset of -5:00).
// This DateTime constructor calls for passing: year, month, day, time zone.
org.joda.time.DateTime dateTimeInNewYork = new org.joda.time.DateTime( 2013, org.joda.time.DateTimeConstants.NOVEMBER, 6, 15, 34, newyorkTimeZone );
// Move to UTC time zone (no offset).
org.joda.time.DateTime dateTimeUtc = dateTimeInNewYork.toDateTime( org.joda.time.DateTimeZone.UTC );
// Move to Kolkata IN time zone (Standard offlet of +05:30).
org.joda.time.DateTime dateTimeInKolkata = dateTimeUtc.toDateTime( kolkataTimeZone ); // Or invoke this method on dateTimeInNewYork, does not matter which.

// All three of these date-time objects represent the same moment in the time-line of the Universe,
// but present themselves with different time-zone offsets.
System.out.println( "dateTimeInNewYork: " + dateTimeInNewYork );
System.out.println( "dateTimeUtc: " + dateTimeUtc );
System.out.println( "dateTimeInKolkata: " + dateTimeInKolkata );

実行時…

dateTimeInNewYork: 2013-11-06T15:34:00.000-05:00
dateTimeUtc: 2013-11-06T20:34:00.000Z
dateTimeInKolkata: 2013-11-07T02:04:00.000+05:30

enter image description here

ジョーダ時について…

// Joda-Time - The popular alternative to Sun/Oracle's notoriously bad date, time, and calendar classes bundled with Java 7 and earlier.
// http://www.joda.org/joda-time/

// Joda-Time will become outmoded by the JSR 310 Date and Time API introduced in Java 8.
// JSR 310 was inspired by Joda-Time but is not directly based on it.
// http://jcp.org/en/jsr/detail?id=310

// By default, Joda-Time produces strings in the standard ISO 8601 format.
// https://en.wikipedia.org/wiki/ISO_8601

// About Daylight Saving Time (DST): https://en.wikipedia.org/wiki/Daylight_saving_time

// Time Zone list: http://joda-time.sourceforge.net/timezones.html
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top