Calendar.getInstance(TimeZone) in Java

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

Syntax:

Calendar java.util.Calendar.getInstance(TimeZone zone)

This method takes one argument of type TimeZone as its parameter. This method gets a calendar using the specified time zone and default locale.The Calendar returned is based on the current time in the given time zone with the default FORMAT locale.

Parameters: One parameter is required for this method.

zone: the time zone to use.

Returns: a Calendar.

Exceptions: NA

Approach

Java

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

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

 System.out.println(Calendar.getInstance(TimeZone.getDefault()));

    }
}

Output:

java.util.GregorianCalendar[time=1642917299887,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=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=0,HOUR=11,HOUR_OF_DAY=11,MINUTE=24,SECOND=59,MILLISECOND=887,ZONE_OFFSET=19800000,DST_OFFSET=0]


No comments:

Post a Comment