开发者社区> 问答> 正文

java怎么获取毫秒时间

java怎么获取毫秒时间

展开
收起
云计算小粉 2018-05-10 20:09:14 3282 0
2 条回答
写回答
取消 提交回答
  • 这个人很懒,所以什么都不想留下~
    System.currentTimeMillis()

    不推荐使用new Date().getTime(),因为Date本身的构造函数里面就是:

    public Date() {
        this(System.currentTimeMillis());
    }

    getTime()中的实现是

    public long getTime() {
        return getTimeImpl();
    }
    
    private final long getTimeImpl() {
        if (cdate != null && !cdate.isNormalized()) {
            normalize();
        }
        return fastTime;
    }

    所以使用new Date().getTime()实质上和直接调用System.currentTimeMillis()功能上没有区别,但是额外执行了很多没用的操作

    2019-07-17 22:18:28
    赞同 1 展开评论 打赏
  • new Date().getTime()
    2019-07-17 22:18:28
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载