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.
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);
Date constructor does take a long (milliseconds) doesn't it?
The question does not mention time zone, so I'll assume you meant UTC/GMT. The question does not explain "ISO format", so I'll assume you meant ISO 8601. This happens to be the default for third-party Joda-Time 2.3 library. This is thread-safe.
// © 2013 Basil Bourque. This source code may be used freely forever by anyone taking full responsibility for doing so. System.out.println( "That moment: " + new org.joda.time.DateTime( 1344855183166L, org.joda.time.DateTimeZone.UTC ) );
That moment: 2012-08-13T10:53:03.166Z<hr>
If the original poster meant a Poland time zone…
// © 2013 Basil Bourque. This source code may be used freely forever by anyone taking full responsibility for doing so. // Time Zone list… http://joda-time.sourceforge.net/timezones.html org.joda.time.DateTimeZone warsawTimeZone = org.joda.time.DateTimeZone.forID( "Europe/Warsaw" ); System.out.println( "That moment in Poland: " + new org.joda.time.DateTime( 1344855183166L, warsawTimeZone ) );
That moment in Poland: 2012-08-13T12:53:03.166+02:00