
Exception in thread "main"
java.time.zone.ZoneRulesException: Unknown time-zone ID: America/NewYork
at java.base/java.time.zone.ZoneRulesProvider.getProvider(ZoneRulesProvider.java:279)
at java.base/java.time.zone.ZoneRulesProvider.getRules(ZoneRulesProvider.java:234)
at java.base/java.time.ZoneRegion.ofId(ZoneRegion.java:120)
at java.base/java.time.ZoneId.of(ZoneId.java:408)
at java.base/java.time.ZoneId.of(ZoneId.java:356)
at org.code2care.Java8AddDaysToDate.main(Java8AddDaysToDate.java:18)
If you get ZoneRulesException runtime exception with message Unknown time-zone ID, that's because you have passed the unknown or incorrect city/country timezone string.
Instant now = Instant.now();
ZonedDateTime zdt = ZonedDateTime.ofInstant(now, ZoneId.of("America/NewYork"));
System.out.println(zdt);
Fix:
In the above example, the NewYork string should be New_York
Instant now = Instant.now();
ZonedDateTime zdt = ZonedDateTime.ofInstant(now, ZoneId.of("America/New_York"));
System.out.println(zdt);
List of Time-Zone ID Strings: https://code2care.org/pages/java-timezone-list-utc-gmt-offset
More Posts related to Java,
- Drop table using Java JDBC Template
- Java - Check if array contains the value
- YAML Parser using Java Jackson Library Example
- Java Jackson ObjectMapper Class with Examples
- Get Client IP address from HTTP Response in Java
- How to Word-Warp Console logs in IntelliJ
- Exception in thread main java.lang.NoClassDefFoundError: package javaClass
- Setting Java_Home Environment variable on Windows Operating System
- Fix: Maven - Failed to execute goal - Compilation failure - Source/Target option 5 is no longer supported. Use 7 or later
- Java SE JDBC Select Statement Example
- How to extract Java Jar/War/Ear files in Linux
- java: unclosed string literal [Error]
- [Solution] Exception in thread main java.util.EmptyStackException
- Read YAML file Java Jackson Library
- What Java version is used for Minecraft 1.18
- [Java] How to throws Exception using Functional Interface and Lambda code
- [Program] How to read three different values using Scanner in Java
- Java 8 Predicate Functional Interface Examples
- Display Era details (AD BC) in Java Date using SimpleDateFormat
- Convert String Date to Date Object in Java
- Struts 2 Hello World Example in Eclipse
- Read a file using Java 8 Stream
- Java - How to set custom thread name?
- IntelliJ: Error: Could not find or load main class, java.lang.ClassNotFoundException
- java: ']' expected error [fixed]
More Posts:
- [Java Threads] Should we extend Thread Class or implement Runnable interface - Java
- Android Studio Native typeface cannot be made error - Android
- [fix] App store not working on Mac, Blank Black or White Screen - MacOS
- How to tar.gz a directory or folder Command - Linux
- Python raise error with message example - Python
- Base 64 Index, Character and Binary Table - Html
- -bash: startup.sh: command not found - Apache Tomcat 8 - Tomcat
- Cannot start Android Studio. No JDK found - Android-Studio