Skip to content
Advertisement

How to convert UTC time into local time in Java?

I have time coming from gpslocation service in 1352437114052 format. Can some one tell me how to convert this into local time either in Java or Matlab or Excel.

Advertisement

Answer

Create a new Date from your milliseconds since epoch. Then use a DateFormat to format it in your desired timezone.

Date date = new Date(1352437114052L);
DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
format.setTimeZone(TimeZone.getTimeZone("PST"));
System.out.println(format.format(date));
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement