![Java Unknown time-zone ID Error Java Unknown time-zone ID Error](https://code2care.org/java/fix-java-time-zone-zonerulesexception-unknown-time-zone-id/images/Java Unknown time-zone ID Error.png)
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,
- Get the current timestamp in Java
- Java Stream with Multiple Filters Example
- Java SE JDBC with Prepared Statement Parameterized Select Example
- Fix: UnsupportedClassVersionError: Unsupported major.minor version 63.0
- [Fix] Java Exception with Lambda - Cannot invoke because object is null
- 7 deadly java.lang.OutOfMemoryError in Java Programming
- How to Calculate the SHA Hash Value of a File in Java
- Java JDBC Connection with Database using SSL (https) URL
- How to Add/Subtract Days to the Current Date in Java
- Create Nested Directories using Java Code
- Spring Boot: JDBCTemplate BatchUpdate Update Query Example
- What is CA FE BA BE 00 00 00 3D in Java Class Bytecode
- Save Java Object as JSON file using Jackson Library
- Adding Custom ASCII Text Banner in Spring Boot Application
- [Fix] Java: Type argument cannot be of primitive type generics
- List of New Features in Java 11 (JEPs)
- Java: How to Add two Maps with example
- Java JDBC Transition Management using PreparedStatement Examples
- Understanding and Handling NullPointerException in Java: Tips and Tricks for Effective Debugging
- Steps of working with Stored Procedures using JDBCTemplate Spring Boot
- Java 8 java.util.Function and BiFunction Examples
- The Motivation Behind Generics in Java Programming
- Get Current Local Date and Time using Java 8 DateTime API
- Java: Convert Char to ASCII
- Deep Dive: Why avoid java.util.Date and Calendar Classes
More Posts:
- How to know file encoding in Microsoft Windows Notepad? - Microsoft
- Submit html form on dropdown menu value selection or change using javascript - JavaScript
- [Android] This view is not constrained vertically: at runtime it will jump to the top unless you add a vertical constraint - Android
- How to adjust MacBook Desktop icons size - MacOS
- How to check if a variable is set in Bash Script or Not - Bash
- How to enable Do Not Disturb (DND) mode in Microsoft Teams - Teams
- Install Bash Completion on macOS - Bash
- Program 10: Modulo of Two Numbers - 1000+ Python Programs - Python-Programs