Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package jp.co.confrage;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.chrono.IsoChronology;
import java.time.format.DateTimeFormatter;
import java.time.format.ResolverStyle;
public class DateTest {
public static void main(String[] args) throws InterruptedException {
String inputValue = "20201230T000000+0800";
ZonedDateTime value =
ZonedDateTime.parse(
inputValue,
DateTimeFormatter.ofPattern("uuuuMMdd'T'HHmmssZ")
.withChronology(IsoChronology.INSTANCE)
.withResolverStyle(ResolverStyle.STRICT));
ZonedDateTime jst = value.withZoneSameInstant(ZoneId.of("Asia/Tokyo"));
System.out.println(jst); // 2020-12-30T01:00+09:00[Asia/Tokyo]
var dt = jst.toLocalDateTime();
System.out.println(dt); // 2020-12-30T01:00
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment