码迷,mamicode.com
首页 > 编程语言 > 详细

Java中的时间

时间:2018-05-14 21:36:54      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:对象   一个   系统   style   table   需要   不能   span   格式   

1.System类获取

  当前时间,System 类不能被实例化,需要通过它的静态方法调用。

  使用System类 currentTimeMillis() 方法,获取当前系统时间。返回以毫秒为单位的时间,值的粒度取决于底层操作系统。

public static long currentTimeMillis()

返回值类型:long

long currentTime = System.currentTimeMillis();
System.out.println(currentTime);

 

2.Date类

   类 Date 表示特定的瞬间,精确到毫秒。

Date 类的构造方法

格式

参数列表

说明

Date() 空参 获取到一个表示当前系统时间的对象
Date(long Date)

long 类型整数,以毫秒计的绝对时间

 

空参获取当前时间,指定 long 类型整数获取 该整数 对应的时间点

System.out.println((new Date())); // 打印当前系统时间
System.out.println(new Date(0)); // 打印绝对时间为 0 的时间点信息
System.out.println(new Date(-3600 * 1000 * 24)); // 打印绝对时间前一天 的时间点信息

 

 

 

 

 

 

 

 

 

a

Java中的时间

标签:对象   一个   系统   style   table   需要   不能   span   格式   

原文地址:https://www.cnblogs.com/argor/p/9037984.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!