マリ:
私はこのような私の日付形式を送信し、外部API(MongoDBのを使用)を使用しています:
"documentDate": 1574283600000,
私はそれのように日付を保持していると思います:
"documentDate" : ISODate("2019-02-28T00:00:00.000+03:00"),
しかし、それは私の番号を返します。どのように私はそれのような適切な日付にすることができます。
03/12/2019
deHaar:
私が使用するjava.time
としてカウントされた時間での瞬間を価値ルックスなど(最も可能性が高い)エポックミリ秒。あなたはそれを変換することができますInstant
し、さらにオフセットまたはタイムゾーンを意識DateTimeオブジェクトに変換します。
これを見ています:
public static void main(String[] args) {
// your sample millis
long documentDateInMillis = 1574283600000L;
// parse it to a moment in time: an Instant
Instant instant = Instant.ofEpochMilli(documentDateInMillis);
// then create an offset aware datetime object by adding an actual offset
OffsetDateTime odt = OffsetDateTime.ofInstant(instant, ZoneOffset.of("+03:00"));
// print it in the default representation
System.out.println("Default formatting:\t" + odt);
// or in an ISO representation of the date only
System.out.println("ISO local date:\t\t"
+ odt.format(DateTimeFormatter.ISO_LOCAL_DATE));
// or in a custom representation (date only, too)
System.out.println("Custom formatting:\t"
+ odt.format(DateTimeFormatter.ofPattern("dd/MM/yyyy")));
}
出力は以下の通りであります:
Default formatting: 2019-11-21T00:00+03:00
ISO local date: 2019-11-21
Custom formatting: 21/11/2019