[Solved] java.time.zone.ZoneRulesException: Unknown time-zone ID: IST


java.time.zone.ZoneRulesException occurs while validating time zone This exception is used to indicate problems with configured time zone rules.

Constructors

  • ZoneRulesException(String message) : Constructs a new date-time exception with the specified message.
  • ZoneRulesException(String message, Throwable cause) : Constructs a new date-time exception with the specified message and cause.

Sample Code

try
{
// Will throw java.time.zone.ZoneRulesException: Unknown time-zone ID: IST
LocalDate todayIST = LocalDate.now(ZoneId.of("IST"));
}
catch(ZoneRulesException ex)
{
ex.printStackTrace();
}

Output Message


java.time.zone.ZoneRulesException: Unknown time-zone ID: IST
    at java.time.zone.ZoneRulesProvider.getProvider(Unknown Source)
    at java.time.zone.ZoneRulesProvider.getRules(Unknown Source)
    at java.time.ZoneRegion.ofId(Unknown Source)
    at java.time.ZoneId.of(Unknown Source)
    at java.time.ZoneId.of(Unknown Source)
    at datetime.Java8DateTime.localDateAPI(Java8DateTime.java:173)
    at datetime.Java8DateTime.main(Java8DateTime.java:34)

Issue

Here with throw ZoneRulesException if pass as Invalidate time-zone. For above example passing time-zone as IST.

Solutions

A ZoneId is unique id with in System which is used to identify rules to convert between Instant and LocalDateTime. Thre are two distict type of ID:

  • Fixed offsets – a fully resolved offset from UTC/Greenwich, that uses the same offset for all local date-times. Most fixed offsets are represented by ZoneoffSet as + or -.
  • Geographical regions – an area where a specific set of rules for finding the offset from UTC/Greenwich apply.

Ex: A time-zone ID, such as Europe/Paris.

Refer below mapping while pass ZoneId value here for above example use Asia/Kolkata as below.

  • HST – -10:00
  • EST – -05:00
  • MST – -07:00
  • ACT – Australia/Darwin
  • AET – Australia/Sydney
  • AGT – America/Argentina/Buenos_Aires
  • ART – Africa/Cairo
  • AST – America/Anchorage
  • BET – America/Sao_Paulo
  • BST – Asia/Dhaka
  • CAT – Africa/Harare
  • CNT – America/St_Johns
  • CST – America/Chicago
  • CTT – Asia/Shanghai
  • EAT – Africa/Addis_Ababa
  • ECT – Europe/Paris
  • IET – America/Indiana/Indianapolis
  • IST – Asia/Kolkata
  • JST – Asia/Tokyo
  • MIT – Pacific/Apia
  • NET – Asia/Yerevan
  • NST – Pacific/Auckland
  • PLT – Asia/Karachi
  • PNT – America/Phoenix
  • PRT – America/Puerto_Rico
  • PST – America/Los_Angeles
  • SST – Pacific/Guadalcanal
  • VST – Asia/Ho_Chi_Minh
try
{
// Will throw java.time.zone.ZoneRulesException: Unknown time-zone ID: IST
LocalDate todayIST = LocalDate.now(ZoneId.of("Asia/Kolkata"));
}
catch(ZoneRulesException ex)
{
ex.printStackTrace();
}

More Issues Solution

For more other JAVA/JDBC issues solution follow link JAVA/JDBC Issues.Sample Code

Output

Advertisements

About Saurabh Gupta

My Name is Saurabh Gupta, I have approx. 11 Year of experience in Information Technology World manly in Java/J2EE. During this time I have worked with multiple organization with different client, so many technology, frameworks etc.
This entry was posted in Java and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s