Calendar setTimeZone(TimeZone) in Java

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

Syntax:

void java.util.Calendar.setTimeZone(TimeZone value)

This method takes one argument of type TimeZone as its parameter. This method sets the time zone with the given time zone value.

Parameters: One parameter is required for this method.

value: the given time zone.

Returns: NA

Exceptions: NA

Approach

Java

import java.util.Calendar;
import java.util.TimeZone;

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

        // create a calendar
        Calendar calendar = Calendar.getInstance();

        TimeZone value = TimeZone.getDefault();
        calendar.setTimeZone(value);

        System.out.println(calendar);
    }
}

Output:

java.util.GregorianCalendar[time=1642959797293,areFieldsSet=false,areAllFieldsSet=false,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/Calcutta",offset=19800000,dstSavings=0,useDaylight=false,transitions=7,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2022,MONTH=0,WEEK_OF_YEAR=5,WEEK_OF_MONTH=5,DAY_OF_MONTH=23,DAY_OF_YEAR=23,DAY_OF_WEEK=1,DAY_OF_WEEK_IN_MONTH=4,AM_PM=1,HOUR=11,HOUR_OF_DAY=23,MINUTE=13,SECOND=17,MILLISECOND=293,ZONE_OFFSET=19800000,DST_OFFSET=0]


No comments:

Post a Comment