Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert millisecond to Joda Date Time or for zone 0000

Tags:

please tell me how to convert milliseconds to joda Date time??

formatter = DateTimeFormat.forPattern("dd/MM/yyyy'T'HH:mm:ss").withZone(DateTimeZone.forOffsetHoursMinutes(00, 00)); 

even tried

String millisecond="14235453511" DateTime.parse(millisecond); 
like image 581
vaibhav Avatar asked Jun 08 '15 13:06

vaibhav


People also ask

Does Joda datetime have time zones?

An interval in Joda-Time represents an interval of time from one instant to another instant. Both instants are fully specified instants in the datetime continuum, complete with time zone.

How do you convert datetime to milliseconds?

How do you convert datetime to milliseconds? A simple solution is to get the timedelta object by finding the difference of the given datetime with Epoch time, i.e., midnight 1 January 1970. To obtain time in milliseconds, you can use the timedelta. total_seconds() * 1000 .

What is Joda-Time format?

Joda-Time provides a comprehensive formatting system. There are two layers: High level - pre-packaged constant formatters. Mid level - pattern-based, like SimpleDateFormat. Low level - builder.

What is Jodatime in Java?

Joda-Time provides a quality replacement for the Java date and time classes. Joda-Time is the de facto standard date and time library for Java prior to Java SE 8. Users are now asked to migrate to java. time (JSR-310). Joda-Time is licensed under the business-friendly Apache 2.0 licence.


1 Answers

The answer given by @Adam S is almost okay. However, I would prefer to specify the timezone explicitly. Without specifying it you get the constructed DateTime-instance in the system timezone. But you want the zone "0000" (UTC)? Then look for this alternative constructor:

String milliseconds = "14235453511"; DateTime someDate = new DateTime(Long.valueOf(milliseconds), DateTimeZone.UTC); System.out.println(someDate); // 1970-06-14T18:17:33.511Z 
like image 88
Meno Hochschild Avatar answered Oct 14 '22 08:10

Meno Hochschild