java.util.Calendar setTimeInMillis()方法

java.util.Calendar.setTimeInMillis() 方法从给定的long值设置日历的当前时间。

1 语法

public void setTimeInMillis(long millis)

2 参数

millis:从纪元UTC新的时间毫秒。

3 返回值

4 示例1 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * java.util.Calendar setTimeInMillis()方法的例子
 */
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());
   }
}

输出结果为:

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

 

热门文章

优秀文章