TimeZone toZoneId() in Java

toZoneId(): This method is available in java.util.TimeZone class of Java.

Syntax:

ZoneId java.util.TimeZone.toZoneId()

This method converts this TimeZone object to a ZoneId.

Parameters: NA

Returns: a ZoneId representing the same time zone as this TimeZone.

Exceptions: NA

Approach

Java

import java.time.ZoneId;
import java.util.SimpleTimeZone;
import java.util.TimeZone;

public class TimeZonetoZoneId {
    public static void main(String[] args) {

        TimeZone timeZone =
new SimpleTimeZone(100, ZoneId.systemDefault().toString());

        System.out.println(timeZone.toZoneId());
    }
}

Output:

Asia/Calcutta


No comments:

Post a Comment