codecamp

Groovy setTime()方法

设置此Date对象以表示一个时间点,即1970年1月1日00:00:00 GMT之后的时间毫秒。

句法

public void setTime(long time)

参数

time - 毫秒数。

返回值

没有

例子

下面是一个使用这个方法的例子 -

class Example { 
   static void main(String[] args) { 
      Date olddate = new Date("05/11/2015"); 
      Date newdate = new Date("05/12/2015"); 
      Date latestdate = new Date();
		
      olddate.setTime(10000); 
      newdate.setTime(10000); 
      latestdate.setTime(10000); 
		
      System.out.println(olddate.toString()); 
      System.out.println(newdate.toString());
      System.out.println(latestdate.toString());  
   } 
}

当我们运行上面的程序,我们将得到以下结果 -

Thu Jan 01 04:00:10 GST 1970 
Thu Jan 01 04:00:10 GST 1970 
Thu Jan 01 04:00:10 GST 1970
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定