search
HomeJavaLocalDate.parse and ResolverStyle.STRICT, for Asia/Hong Kong, return unexpected results

php editor Xiaoxin will introduce the issues about LocalDate.parse and ResolverStyle.STRICT in Java in this article. When using these methods in Asia or Hong Kong, you may get unexpected results. We will explore this issue and provide solutions.

Question content

My input is 19.12.0009, the expected value is dec 19 00:00:00 hkt 9, but the returned result is dec 21 00:23:18 hkt 9, why? code show as below:

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.uuuu")
                        .withResolverStyle(ResolverStyle.STRICT);
LocalDate localDate = LocalDate.parse("19.12.0009", formatter);
Instant instant = Instant.from(localDate.atStartOfDay(ZoneId.of("Asia/Hong_Kong")));
Date resultDate = Date.from(instant);
System.out.println("resultDate" + resultDate);

Solution

There is a concept of transition in zonerules, which has savingslocaltransitions. I found that for some reason (probably historical), the savings in "asia/hong_kong" local conversion start at 1904-10-30t00:36:42. resolverstyle.strict Not the problem here!

That's why you see 00:23:18 hkt 9.

If you change the code, for example:

localdate localdate = localdate.parse("19.12.1904", formatter);

Expected output:

resultDate Mon Dec 19 01:00:00 JST 1904

The above is the detailed content of LocalDate.parse and ResolverStyle.STRICT, for Asia/Hong Kong, return unexpected results. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:stackoverflow. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function