如何从Java的时间(毫秒)获取ISO格式? [英] How to get ISO format from time in milliseconds in Java?

查看:173
本文介绍了如何从Java的时间(毫秒)获取ISO格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从以毫秒为单位的时间获取 yyyy-MM-dd HH:mm:ss,SSS 的简单方法?我已经从 new Date() Calendar.getInstance()中找到一些信息,但是可以不能确定是否可以从长期完成(例如 1344855183166

解决方案

p>我以为你问过如何使用这种格式的时间yyyy-MM-dd HH:mm:ss,SSS



一种方法是使用java SimpleDateFormat:
http://docs.oracle .com / javase / 6 / docs / api / java / text / SimpleDateFormat.html



请注意,这不是线程安全的。

...

 日期d =新日期(1344855183166L); 
SimpleDateFormat sdf = new SimpleDateFormat(yyyy-MM-dd HH:mm:ss,SSS);
String dateStr = sdf.format(d);

...


Is it simple way to get yyyy-MM-dd HH:mm:ss,SSS from time in millisecond? I've found some information how to do this from new Date() or Calendar.getInstance(), but couldn't find if it can be done from long (e.g. 1344855183166)

解决方案

I thought you had asked how to get the time in this format "yyyy-MM-dd HH:mm:ss,SSS"

One way is to use java's SimpleDateFormat: http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html

NOTE that this is not thread-safe.

...

Date d = new Date(1344855183166L);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS");
String dateStr = sdf.format(d);

...

这篇关于如何从Java的时间(毫秒)获取ISO格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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