TimeZone getOffset(int, int, int, int, int, int) in Java

getOffset(int, int, int, int, int, int): This method is available in java.util.TimeZone class of Java.

Syntax:

int java.util.TimeZone.getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds)

This method takes six arguments. This method gets the time zone offset, for the current date, modified in case of daylight savings. This is the offset to add to UTC to get local time.

Parameters: Six parameters are required for this method.

era: the era of the given date.

year: the year on the given date.

month: the month on the given date.

day: the day-in-month of the given date.

dayOfWeek: the day-of-week of the given date.

milliseconds: the milliseconds in day in standard local time.

Returns: the offset in milliseconds to add to GMT to get local time.

Exceptions: NA

Approach

Java

import java.util.SimpleTimeZone;
import java.util.TimeZone;

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

        TimeZone timeZone = new SimpleTimeZone(100, "US");

        int era = 1, year = 2022, month = 5,
day = 10, dayOfWeek = 3, millisecond = 1000;

        System.out.println(timeZone.getOffset(era,
year, month, day, dayOfWeek, millisecond));
    }
}

Output:

100


No comments:

Post a Comment