System获取当前系统时间

来源:互联网 发布:手机抢单送外卖软件 编辑:程序博客网 时间:2024/06/04 21:03
public class SystemGetTimeDemo {


public static void main(String[] args) throws InterruptedException {
//获取当前系统时间与UTC1970年1月1日午夜时间的差
long startTime = System.currentTimeMillis();;//此为毫秒为单位
Thread.sleep(1000);
long endTime = System.currentTimeMillis();
System.currentTimeMillis();
//时间差
System.out.println(endTime-startTime);
long nanoTime = System.nanoTime();//此为纳秒为单位
System.out.println(nanoTime);
}
}
0 0
原创粉丝点击