Java.util.Calendar.setTimeInMillis() Method



Description

The java.util.Calendar.setTimeInMillis(long) method sets Calendar's current time from the given long value.

Declaration

Following is the declaration for java.util.Calendar.setTimeInMillis() method

public void setTimeInMillis(long millis)

Parameters

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

Return Value

This method does not return a value.

Exception

NA

Example

The following example shows the usage of java.util.calendar.setTimeInMillis() method.

package com.tutorialspoint;

import java.util.*;

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

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

      // get the time in milliseconds
      System.out.println("Current time is :" + cal.getTime());

      // set time to 5000 ms after january 1 1970
      cal.setTimeInMillis(5000);

      // print the new time
      System.out.println("After setting Time:  " + cal.getTime());
   }
}

Let us compile and run the above program, this will produce the following result −

Current time is :Wed May 02 20:36:23 EEST 2012
After setting Time:  Thu Jan 01 02:00:05 EET 1970
java_util_calendar.htm
Advertisements