Java 8 ZoneId class

The java.time.LocalDate class is an immutable class without a time-zone in the ISO-8601 calendar system, such as 2018-04-03.

Java ZoneId class methods

Method Description
String getDisplayName(TextStyle style, Locale locale) It is used to get the textual representation of the zone, such as ‘India Time’ or ‘+05:30’.
abstract String getId() It is used to get the unique time-zone ID.
static ZoneId of(String zoneId) It is used to obtain an instance of ZoneId from an ID ensuring that the ID is valid and available for use.
static ZoneId systemDefault() It is used to get the system default time-zone.
boolean equals(Object obj) It is used to check if this time-zone ID is equal to another time-zone ID.


Example

package com.w3schools;
 
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.format.TextStyle;
import java.util.Locale;
 
public class TestExample {
	public static void main(String args[]){
	    ZoneId zoneid1 = ZoneId.of("Asia/Kolkata");  
	    ZoneId zoneid2 = ZoneId.of("Asia/Tokyo");  
	    LocalTime localTime1 = LocalTime.now(zoneid1);  
	    LocalTime localTime2 = LocalTime.now(zoneid2);  
	    System.out.println(localTime1);  
	    System.out.println(localTime2);  
	    System.out.println(localTime1.isBefore(localTime2));
 
	    //System default
	    ZoneId zone = ZoneId.systemDefault();     
	    System.out.println(zone);  
 
	    //Get id
	    System.out.println(zone.getId()); 
 
	    //Display name
	    System.out.println(zone.getDisplayName(TextStyle.FULL, Locale.ROOT)); 
	}  
}

Output

19:13:16.490
22:43:16.490
true
Asia/Calcutta
Asia/Calcutta
India Time