GregorianCalendar setTimeInMillis(long) in Java

setTimeInMillis(long): This method is available in java.util.GregorianCalendar class of Java.

Syntax:

void java.util.Calendar.setTimeInMillis(long millis)

This method takes one argument of type long as its parameter. This method sets this Calendar's current time from the given long value.

Parameters: One parameter is required for this method.

millis: the new time in UTC milliseconds from the epoch.

Returns: NA

Exceptions: NA

Approach

Java

import java.util.GregorianCalendar;

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

        GregorianCalendar cal = new GregorianCalendar();

        long millis = 199199119;
        cal.setTimeInMillis(millis);
        System.out.println(cal);
    }
}

Output:

java.util.GregorianCalendar[time=199199119,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=1970,MONTH=0,WEEK_OF_YEAR=1,WEEK_OF_MONTH=1,DAY_OF_MONTH=3,DAY_OF_YEAR=3,DAY_OF_WEEK=7,DAY_OF_WEEK_IN_MONTH=1,AM_PM=1,HOUR=0,HOUR_OF_DAY=12,MINUTE=49,SECOND=59,MILLISECOND=119,ZONE_OFFSET=19800000,DST_OFFSET=0]


No comments:

Post a Comment