2012-11-09 238 views
3

我有时间来自1352437114052格式的gpslocation服务。有人能告诉我如何在Java或Matlab或Excel中将其转换为本地时间。如何将UTC时间转换为Java中的本地时间?

+0

找出本地时间之间的偏移UTC以毫秒为单位,并从您在此处的值中加/减。自1970年以来,您的时区以毫秒为单位给出当地时间。 –

+0

类似问题,[GPS时间表示库](http://stackoverflow.com/q/3038229/642706)和[毫秒到UTC格式的GPS时间](http://stackoverflow.com/q/9599176/642706) 。 –

回答

3

纪元以来的创建从毫秒新Date。然后使用DateFormat将其格式化为所需的时区。

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)); 
4

这是一个epoch time它代表Fri,09 Nov 2012 04:58:34 GMT。该数值是绝对时间点,与时区无关。

如果你想看到在不同的时区的时间点,用GregorianCalendar

Calendar c = new GregorianCalendar(TimeZone.getTimeZone("EST")); 
c.setTimeInMillis(1352437114052L); 
c.get(Calendar.HOUR_OF_DAY); //20:58 the day before 
+0

关键是使用'TimeZone'。否则,你会得到默认区域。 –

+0

使用'DateTime converted = c.getTime();'获得转换日期时间 – wooohoh

0

@Steve Kuo直接回答了这个问题。下面是机器的本地时间更广泛的解决方案,包括夏令时,其中aBasicFileAttributes类型为中Files.walkFileTreepublic FileVisitResult visitFile(Path f, BasicFileAttributes a)的Windows目录条目报道:

String modifyDate; 
    Date date = new Date(a.lastModifiedTime().to(TimeUnit.MILLISECONDS)); 
    DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); 
    format.setTimeZone(TimeZone.getDefault()); 
    modifyDate = (format.format(date)).substring(0,10); 
相关问题