How to convert date to UTC

I need to change the date format in UTC.

File file = new File ();

...

file.lastModified ();

I need to convert lastModified file date to UTC.

+2
java date
Mar 10 '11 at 18:52
source share
2 answers
String lv_dateFormateInUTC=""; //Will hold the final converted date SimpleDateFormat lv_formatter = new SimpleDateFormat(); lv_formatter.setTimeZone(TimeZone.getTimeZone("UTC")); lv_dateFormateInUTC = lv_formatter.format(lv_localDate); 

Something like that...!!

+16
Mar 10 '11 at 19:00
source share

Pretty simple:

 Date date = new Date(file.lastModified()) 

This works because the long value returned by File.lastModified() is the number of milliseconds since the epoch (00:00:00 GMT, January 1, 1970), as stated in Javadoc . The same can be said of java.util.Date . Thus, they are already in UTC / GMT. When a date is converted to a string, for example via Date.toString() or DateFormat , it is usually expressed in the local time zone, but the long value stores are time-agnostic.

+6
Mar 10 2018-11-11T00:
source share



All Articles