GregorianCalendar.getInstance(TimeZone, Locale) in Java

GregorianCalendar.getInstance(TimeZone, Locale): This method is available in java.util.GregorianCalendar class of Java.

Syntax:

Calendar java.util.Calendar.getInstance(TimeZone zone, Locale aLocale)

This method takes two arguments. This method gets a calendar with the specified time zone and locale. The Calendar returned is based on the current time in the given time zone with the given locale.

Parameters: Two parameters are required for this method.

zone: the time zone to use.

aLocale: the locale for the week data.

Returns: a Calendar.

Exceptions: NA

Approach

Java

import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;

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

        TimeZone zone = TimeZone.getDefault();
        Locale locale = Locale.CANADA;
        System.out.println(GregorianCalendar.
getInstance(zone, locale));

    }
}

Output:

java.util.GregorianCalendar[time=1644160558769,areFieldsSet=true,areAllFieldsSet=true,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=1,WEEK_OF_YEAR=7,WEEK_OF_MONTH=2,DAY_OF_MONTH=6,DAY_OF_YEAR=37,DAY_OF_WEEK=1,DAY_OF_WEEK_IN_MONTH=1,AM_PM=1,HOUR=8,HOUR_OF_DAY=20,MINUTE=45,SECOND=58,MILLISECOND=769,ZONE_OFFSET=19800000,DST_OFFSET=0]


No comments:

Post a Comment