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

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

问题描述

下面的代码给了我当前时间.但它没有说明任何关于毫秒的信息.

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;
}

我有一个格式为 YYYY-MM-DD HH:MM:SS (2009-09-22 16:47:08) 的日期.

I have a date in the format YYYY-MM-DD HH:MM:SS (2009-09-22 16:47:08).

但我想以 YYYY-MM-DD HH:MM:SS.MS (2009-09-22 16:47:08.128>,其中 128 是毫秒).

But I want to retrieve the current time in the format YYYY-MM-DD HH:MM:SS.MS (2009-09-22 16:47:08.128, where 128 are the milliseconds).

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");

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

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