Parad0X:
私は現在のロケールからの時間をフォーマットしますが、常に特定のロケールUTC + 1、または特定の状態からカント私はアプリケーションを作成日付形式に問題がありますが、私はどのように知りません。
SimpleDateFormat("d.M.yyyy HH:mm", Locale.getDefault()).format(Date(date))
私は物理的な位置や電話の設定に依存しない定数などのセットのロケールまたはタイムゾーンを必要としています。
私はUTC-0で常にデータを持っているが、私はUTC + 1(またはその他)に変換し、ユーザーに見せる必要が。
任意の助けてくれてありがとう
時間同期のために私はTrueTimeライブラリを使用します
deHaar:
ここでjava.time
使用した例ZonedDateTime
である時間の瞬間、から作成さInstant
れたパッケージでは:
public static void main(String[] args) {
// get a representation of a moment in time (not a specific date or time)
Instant now = Instant.now();
// then use that in order to represent it in a specific zone using an offset of -1 hour
ZonedDateTime utcZdt = ZonedDateTime.ofInstant(now, ZoneOffset.ofHours(-1));
// and use it again in order to have another one defined by a specific time zone
ZonedDateTime laZdt = ZonedDateTime.ofInstant(now, ZoneId.of("America/Los_Angeles"));
// and print the representation as String
System.out.println(utcZdt.format(DateTimeFormatter.ISO_ZONED_DATE_TIME));
System.out.println(laZdt.format(DateTimeFormatter.ISO_ZONED_DATE_TIME));
}
出力は、
2020-02-18T14:31:21.714-01:00
2020-02-18T07:31:21.714-08:00[America/Los_Angeles]
あなたは、代わりに使用することができますOffsetDateTime
同じパッケージのを。
キーは使用することですInstant
エポックミリ秒から派生し、。これらのミリ秒の値は、あまりにも、時間にゾーンまたはオフセットから独立した瞬間です。
あなたが使用する必要がある場合がありますので、あなたは、AndroidアプリをコーディングしているThreeTenABP、ほぼ全体のバックポートjava.time
Androidの26以下のAPIレベルのための機能を。
私が使用して、今日では、それを考えるjava.time
かのバックポートは、少なくとも面倒とあなたのようなタスクを解決するための最も直接的な方法です。