Last active
August 10, 2016 06:32
-
-
Save MenoData/74e8e8d87d91669203ab4cae8e5330b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.time.*; | |
import net.time4j.*; | |
import net.time4j.format.expert.*; | |
import java.util.Locale; | |
public class DoubleTimeAndZoneInfo { | |
private static final ChronoFormatter<Moment> FORMATTER = | |
ChronoFormatter.setUp(Moment.axis(), Locale.US) | |
.addPattern("HHmm z (", PatternType.CLDR) | |
.skipUnknown(c -> c != ')', 10) // skips second hour/minute/zone-info (potentially ambivalent) | |
.addPattern(") MMMM dd, uuuu", PatternType.CLDR) | |
.build(); | |
public static void main(String... args) throws ParseException { | |
String input = "0022 GMT (0822 HKT) July 21, 2016"; | |
Moment moment = FORMATTER.parse(input); | |
System.out.println("Moment=" + moment); // 2016-07-21T00:22:00Z | |
// conversion to JSR-310-type | |
Instant instant = moment.toTemporalAccessor(); | |
System.out.println("Instant=" + instant); // 2016-07-21T00:22:00Z | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment