Calendar setTimeInMillis(long) in Java

setTimeInMillis(long): This method is available in java.util.Calendar 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.Calendar;

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

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

        long millis = 12772727;
        calendar.setTimeInMillis(millis);

        System.out.println(calendar);
    }
}

Output:

java.util.GregorianCalendar[time=12772727,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=1,DAY_OF_YEAR=1,DAY_OF_WEEK=5,DAY_OF_WEEK_IN_MONTH=1,AM_PM=0,HOUR=9,HOUR_OF_DAY=9,MINUTE=2,SECOND=52,MILLISECOND=727,ZONE_OFFSET=19800000,DST_OFFSET=0]


No comments:

Post a Comment