如何获取当前时间在YYYY-MM-DD HH:MI:Sec.Millisecond格式在Java? [英] How to get the current time in YYYY-MM-DD HH:MI:Sec.Millisecond format in Java?

查看:325
本文介绍了如何获取当前时间在YYYY-MM-DD HH:MI:Sec.Millisecond格式在Java?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码给了我当前的时间。但是毫秒之内并没有告诉任何事情。

The code below gives me the current time. But it does not tell anything about milliseconds.

public static String getCurrentTimeStamp() {
    SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//dd/MM/yyyy
    Date now = new Date();
    String strDate = sdfDate.format(now);
    return strDate;
}

我以格式 2009-09- 22 16:47:08 (YYYY-MM-DD HH:MI:Sec)。

I get date in the format 2009-09-22 16:47:08 (YYYY-MM-DD HH:MI:Sec).

但是我想要检索当前的时间格式 2009-09-22 16:47:08.128 ((YYYY-MM-DD HH:MI:Sec.Ms)。

But I want to retrieve the current time in the format 2009-09-22 16:47:08.128 ((YYYY-MM-DD HH:MI:Sec.Ms).

其中128告诉毫秒。

SimpleTextFormat可以正常工作,这里最低的时间是第二,但是如何获得毫秒?

SimpleTextFormat will work fine. Here the lowest unit of time is second, but how do I get millisecond as well?

推荐答案

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");

这篇关于如何获取当前时间在YYYY-MM-DD HH:MI:Sec.Millisecond格式在Java?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆