How to display all UTC offset in Java 8


In Java 8, we can use ZoneId.getAvailableZoneIds() to get all unique zone id and LocalDateTime to get UTC offset of that zone id.

1. Stream API

GetAllUTC.java
package org.websparrow.java8;

import java.time.LocalDateTime;
import java.time.ZoneId;

public class GetAllUTC {

	public static void main( String[] args ) {

		LocalDateTime localDateTime = LocalDateTime.now();

		ZoneId.getAvailableZoneIds()
			.stream()
			.map( ZoneId::of )
			.map( zoneId -> localDateTime.atZone( zoneId )
				.getOffset()
				.getId()
				.replaceAll( "Z", "+00:00" ) )
			.forEach( e -> System.out.println( "UTC " + e ) );
	}
}

2. Enhanced For Loop

LocalDateTime localDateTime = LocalDateTime.now();

for ( String zoneId : ZoneId.getAvailableZoneIds() ) {

	String utc = localDateTime.atZone( ZoneId.of( zoneId ) )
		.getOffset()
		.getId()
		.replaceAll( "Z", "+00:00" );
	System.out.println( "UTC " + utc );
}
console
UTC +03:00
UTC -04:00
UTC -09:00
UTC -08:00
UTC +03:00
UTC -04:00
UTC +05:00
UTC +12:00
UTC -06:00
UTC +07:00
UTC +02:00
UTC -11:00
UTC +02:00
UTC +08:00
UTC -10:00
UTC -10:00
UTC -06:00
UTC +10:00
UTC +01:00
UTC -06:00
UTC -05:00
UTC +08:00
UTC -06:00
UTC -04:00
UTC +04:00
UTC +02:00
UTC +00:00
UTC +02:00
UTC -05:00
UTC +06:00
UTC -04:00
UTC +10:00
UTC +02:00
UTC +01:00
UTC +00:00
UTC +01:00
UTC -06:00
UTC +05:00
UTC +03:00
UTC -05:00
UTC +04:00
UTC -02:00
UTC +03:00
UTC +02:00
UTC +02:00
UTC +09:00
UTC -03:00
UTC +08:00
UTC +07:00
UTC +06:00
UTC +03:00
UTC -07:00
UTC -03:00
UTC +00:00
UTC +10:00
UTC +02:00
UTC +01:00
UTC -04:00
UTC -07:00
UTC +05:00
UTC -03:00
UTC +07:00
UTC +02:00
UTC +06:00
UTC -08:00
UTC +04:00
UTC +01:00
UTC -03:00
UTC -04:00
UTC +07:00
UTC -03:00
UTC -03:00
UTC +01:00
UTC -02:00
UTC -01:00
UTC +13:00
UTC +02:00
UTC +00:00
UTC +03:00
UTC +00:00
UTC -07:00
UTC +03:00
UTC -06:00
UTC -05:00
UTC -04:00
UTC +10:00
UTC -07:00
UTC +03:00
UTC +04:00
UTC +09:00
UTC +02:00
UTC -03:00
UTC +02:00
UTC +05:00
UTC +03:00
UTC +08:00
UTC -03:00
UTC +00:00
UTC +09:00
UTC -06:00
UTC +07:00
UTC +12:00
UTC +08:00
UTC -04:00
UTC +00:00
UTC +03:00
UTC +07:00
UTC -03:00
UTC +08:00
UTC +02:00
UTC -06:00
UTC -10:00
UTC +03:00
UTC +02:00
UTC -03:00
UTC +01:00
UTC +02:00
UTC -03:00
UTC -02:00
UTC +02:00
UTC +10:00
UTC +01:00
UTC +01:00
UTC -03:00
UTC +02:00
UTC +06:00
UTC +04:00
UTC -11:00
UTC -06:00
UTC -04:00
UTC -07:00
UTC +01:00
UTC +03:00
UTC -02:30
UTC -04:00
UTC +02:00
UTC -04:00
UTC +09:00
UTC -06:00
UTC +00:00
UTC +04:00
UTC +01:00
UTC -05:00
UTC +12:00
UTC +02:00
UTC +00:00
UTC +02:00
UTC +03:00
UTC -04:00
UTC +12:45
UTC +08:00
UTC -05:00
UTC +06:00
UTC +02:00
UTC -04:00
UTC +06:00
UTC -04:00
UTC +03:00
UTC -01:00
UTC +05:00
UTC -04:00
UTC -10:00
UTC +12:45
UTC +02:00
UTC -03:00
UTC +09:00
UTC -04:00
UTC +05:00
UTC -04:00
UTC -05:00
UTC -04:00
UTC +01:00
UTC +02:00
UTC +03:00
UTC +03:00
UTC -04:00
UTC -05:00
UTC +11:00
UTC +02:00
UTC +02:00
UTC -03:00
UTC +08:45
UTC +08:00
UTC +00:00
UTC +02:00
UTC -04:00
UTC +03:00
UTC +03:00
UTC +03:00
UTC +11:00
UTC -05:00
UTC +01:00
UTC +06:00
UTC -03:00
UTC +09:00
UTC -06:00
UTC +09:30
UTC +02:00
UTC +01:00
UTC +12:00
UTC -05:00
UTC +05:00
UTC +09:30
UTC -04:00
UTC +05:00
UTC -06:00
UTC +13:00
UTC -08:00
UTC +10:00
UTC -04:00
UTC +05:00
UTC +07:00
UTC +02:00
UTC +07:00
UTC -03:00
UTC -03:00
UTC -02:00
UTC -06:00
UTC +09:30
UTC -08:00
UTC +03:00
UTC -03:00
UTC +03:00
UTC +03:00
UTC +00:00
UTC +02:00
UTC -04:00
UTC +05:00
UTC -04:00
UTC +02:00
UTC +04:00
UTC +07:00
UTC -04:00
UTC -09:00
UTC -04:00
UTC -06:00
UTC -04:00
UTC +12:00
UTC +00:00
UTC +11:00
UTC -07:00
UTC -03:00
UTC +02:00
UTC +10:00
UTC +09:00
UTC -04:00
UTC +03:00
UTC +00:00
UTC -07:00
UTC +01:00
UTC +06:00
UTC -02:30
UTC -04:00
UTC -08:00
UTC +07:00
UTC +08:00
UTC +02:00
UTC +03:00
UTC +00:00
UTC +02:00
UTC +09:00
UTC -08:00
UTC -06:00
UTC +10:00
UTC +12:00
UTC +02:00
UTC +05:30
UTC -07:00
UTC +10:00
UTC +02:00
UTC +09:30
UTC +03:00
UTC -04:00
UTC +00:00
UTC -03:00
UTC -03:00
UTC +12:00
UTC -04:00
UTC +08:00
UTC +12:00
UTC -06:00
UTC +10:00
UTC -04:00
UTC +10:00
UTC +12:00
UTC -03:00
UTC -06:00
UTC -07:00
UTC +08:00
UTC +01:00
UTC +02:00
UTC -05:00
UTC -05:00
UTC +00:00
UTC +01:00
UTC -07:00
UTC -03:00
UTC +00:00
UTC +13:00
UTC +00:00
UTC -09:00
UTC -11:00
UTC +10:30
UTC +01:00
UTC +10:00
UTC -06:00
UTC -05:00
UTC -04:00
UTC -05:00
UTC +06:00
UTC -05:00
UTC -03:00
UTC +10:00
UTC -10:00
UTC -06:00
UTC +04:00
UTC +05:00
UTC -08:00
UTC +10:00
UTC +01:00
UTC +02:00
UTC +00:00
UTC -04:00
UTC +01:00
UTC +00:00
UTC -05:00
UTC -09:30
UTC -04:00
UTC -04:00
UTC -05:00
UTC -05:00
UTC +08:00
UTC +03:00
UTC +02:00
UTC -05:00
UTC -07:00
UTC +10:00
UTC -09:00
UTC +01:00
UTC -06:00
UTC -06:00
UTC +07:00
UTC -08:00
UTC -06:00
UTC -03:00
UTC -03:00
UTC -04:00
UTC -06:00
UTC +03:00
UTC -03:00
UTC -04:00
UTC +04:00
UTC -03:00
UTC +00:00
UTC +01:00
UTC +01:00
UTC -04:00
UTC +10:00
UTC +08:00
UTC +12:00
UTC +08:00
UTC +07:00
UTC +03:00
UTC +02:00
UTC +01:00
UTC -03:00
UTC -04:00
UTC +03:00
UTC +06:30
UTC +03:00
UTC -02:00
UTC +05:00
UTC +00:00
UTC -04:00
UTC -07:00
UTC -03:00
UTC -05:00
UTC +06:00
UTC +03:00
UTC +02:00
UTC -11:00
UTC +08:00
UTC +07:00
UTC +14:00
UTC -05:00
UTC -04:00
UTC +03:00
UTC +00:00
UTC +11:00
UTC +08:00
UTC -02:00
UTC +01:00
UTC +08:00
UTC +02:00
UTC +07:00
UTC -05:00
UTC +01:00
UTC -05:00
UTC +03:00
UTC -10:00
UTC +11:00
UTC +00:00
UTC -05:00
UTC -05:00
UTC -09:00
UTC +11:00
UTC +03:00
UTC -05:00
UTC +12:00
UTC +03:00
UTC +07:00
UTC +00:00
UTC -05:00
UTC -06:00
UTC +02:00
UTC +09:30
UTC -05:00
UTC +02:00
UTC -04:00
UTC -04:00
UTC +03:00
UTC +12:00
UTC +01:00
UTC -03:00
UTC -04:00
UTC +03:00
UTC +03:00
UTC +08:00
UTC +11:00
UTC -08:00
UTC -04:00
UTC +01:00
UTC -04:00
UTC +05:00
UTC +01:00
UTC -04:00
UTC +02:00
UTC -05:00
UTC +04:00
UTC +03:00
UTC +03:00
UTC -03:00
UTC +00:00
UTC -04:00
UTC -07:00
UTC -05:00
UTC +02:00
UTC +11:00
UTC +01:00
UTC +05:45
UTC +09:00
UTC +10:00
UTC -05:00
UTC +10:30
UTC -04:00
UTC +02:00
UTC -05:00
UTC -04:00
UTC +08:00
UTC -07:00
UTC -06:00
UTC -06:00
UTC +05:30
UTC +08:00
UTC +03:00
UTC +10:00
UTC +03:00
UTC -05:00
UTC +06:00
UTC -09:00
UTC +03:00
UTC -04:00
UTC -07:00
UTC +02:00
UTC -05:00
UTC +00:00
UTC -04:00
UTC -03:00
UTC +02:00
UTC +08:00
UTC +04:30
UTC -03:00
UTC +00:00
UTC -05:00
UTC -04:00
UTC -04:00
UTC +11:00
UTC -10:00
UTC +00:00
UTC +12:00
UTC +06:00
UTC +02:00
UTC -12:00
UTC -11:00
UTC -06:00
UTC -08:00
UTC +03:00
UTC +03:00
UTC +02:00
UTC +02:00
UTC +01:00
UTC +02:00
UTC -05:00
UTC +00:00
UTC +04:30
UTC +01:00
UTC +04:00
UTC +03:00
UTC -04:00
UTC -03:00
UTC +00:00
UTC +07:00
UTC -07:00
UTC -11:00
UTC -03:00
UTC +00:00
UTC -03:00
UTC -03:00
UTC -04:00
UTC -04:00
UTC +05:45
UTC -07:00
UTC +01:00
UTC -07:00
UTC +11:00
UTC +04:00
UTC -04:00
UTC +08:00
UTC -03:00
UTC +08:00
UTC +00:00
UTC +03:00
UTC -04:00
UTC -06:00
UTC -03:00
UTC -04:00
UTC -04:00
UTC +05:00
UTC +09:30
UTC +09:00
UTC +08:00
UTC +03:00
UTC +06:00
UTC +06:30
UTC +02:00
UTC +05:30
UTC -03:00
UTC +04:30
UTC +06:30
UTC +09:00
UTC +13:00
UTC -04:00
UTC +12:00
UTC +11:00
UTC +10:00
UTC -08:00
UTC +04:00
UTC +14:00
UTC +13:00
UTC +03:00
UTC -05:00
UTC +03:00
UTC -03:00
UTC -06:00
UTC -04:00
UTC +02:00
UTC -07:00
UTC -04:00
UTC -04:00
UTC +03:00
UTC +05:00
UTC -07:00
UTC +00:00
UTC +10:00
UTC +02:00
UTC +11:00
UTC -05:00
UTC +12:00
UTC +10:00
UTC +08:00
UTC -06:00
UTC -05:00
UTC +02:00
UTC +03:00
UTC +00:00
UTC -03:00
UTC +09:00
UTC -04:00
UTC +08:00
UTC +10:00
UTC -07:00
UTC -04:00
UTC +12:00
UTC -03:00
UTC +03:00
UTC +11:00
UTC +03:00
UTC -07:00
UTC +02:00

References

  1. Class ZoneId
  2. Java 8– Calculate date & time difference between two Zone
  3. Java 8 – Difference between two LocalDate
  4. Java 8 – Calculate difference between two LocalDateTime

Similar Posts

About the Author

Atul Rai
I love sharing my experiments and ideas with everyone by writing articles on the latest technological trends. Read all published posts by Atul Rai.