
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,
- Convert Java Map Collection Object to JSON String using Jackson
- Java Stream flatmap() Examples
- [Fix] Instant java.time.temporal.UnsupportedTemporalTypeException: Unsupported unit: Years
- How to run Java Unit Test cases with Apache Maven?
- How to check if Java main thread is alive
- [Fix] java: incompatible types: incompatible parameter types in lambda expression error
- Parsing CSV file using Java code example (Comma Separated File)
- Unhandled exception type InterruptedException : Java Threads
- Native getClass() method from java.lang.Object Class Explained with examples.
- Java Jackson ObjectMapper Class with Examples
- Java 8 Streams map() with examples
- Java 8 - Convert List to Map Examples
- IntelliJ: Error: Could not find or load main class, java.lang.ClassNotFoundException
- Java Stream with Multiple Filters Example
- How to Clear StringJoiner in Java 8
- Spring 5 IoC Example with application Context XML (ClassPathXmlApplicationContext) and Gradle.
- How to get end of line (EOL) or new line character \r \n in Java
- Spring Boot CRUD Examples using JDBCTemplate
- Delete a File in Java with Examples
- Implementing Insertion Sort Algorithm in Java Program
- Java JDBC Batch Update Example with PreparedStatement
- Java JDBC Select Multiple Records from table as List using PreparedStatement
- [Hibernate] The method buildSessionFactory() from the type Configuration is deprecated
- How to fix Java HTTP java.net.UnknownHostException
- Java 8 Display time in 12 hour AM PM format
More Posts:
- Java Jackson ObjectMapper Class with Examples - Java
- Java: Generate random numbers within a range - Java
- Cannot access files within Microsoft Teams - We are setting up your file directory - Teams
- How to save a file as csv in Windows Notepad? - Microsoft
- Jupyter Notebook: 404 : Not Found - You are requesting a page that does not exist! - Python
- Python: How to POST Json Data with HTTP Request - Python
- How to Open .bash_profile file in Mac Terminal - MacOS
- Mac OS X Taking Screen Capture using Terminal - Mac-OS-X