System.currentTimeMillis()(摘)

首先System.currentTimeMillis()产生一个当前的毫秒,这个毫秒其实就是自1970年1月1日0时起的毫秒数,Date()其实就是相当于Date(System.currentTimeMillis());因为Date类还有构造Date(long date),用来计算long秒与1970年1月1日之间的毫秒差。
      得到了这个毫秒数,我们自己也可以算起现在的年月日周时,但是这不是我们去计算的,因为有Calendar。Calendar最终出的结果就是年月日周时时区。

import java.text.SimpleDateFormat;
import java.util.Date;


public class TimeTest {

 public static void main(String arg[]){
  long startTime = System.currentTimeMillis();
        Date date = new Date(startTime);
        System.out.println(date);
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//格式转化
        System.out.println(sdf.format(date));
        
        long endTime = System.currentTimeMillis();

  System.out.println("运行时间:"+(endTime - startTime)+"毫秒");
 }
}

 

转载于:https://www.cnblogs.com/HelloGuang/p/3468156.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值