我已阅读Google Directions API的文档以发出指示请求。 URL的示例以
的形式给出http://maps.googleapis.com/maps/api/directions/json?origin=Brooklyn&destination=Queens&sensor=false&departure_time=1343605500&mode=transit
departure_time
变量的值应该反映以下信息:
2012年7月30日上午09:45。
有人可以解释这种时间格式。
感谢。
答案 0 :(得分:3)
这是一个时间戳 - 自Unix epoch,1970-01-01 00:00:00 UTC以来经过的秒数。如果您希望以该格式“立即”使用System.currentTimeMillis() / 1000
,或者如果您拥有Date
对象,则可以使用date.getTime() / 1000
。
答案 1 :(得分:1)
这是一个纪元unix时间戳(自1970年1月1日以来的秒数)。您可以按
创建日期Date d = new Date(1343605500L);
答案 2 :(得分:0)
搜索该特定号码会导致this similar StackOverflow.com question等地点。这些页面让我得出结论,Google Directions API的文档存在缺陷。
您和其他人报告该文件称1343605500 = 2012年7月30日上午09:45在纽约。但这是不正确的。月份和日期都是错误的。
从UTC 1970年/格林威治标准时间开始的 1343605500
秒:
2012-07-29T19:45:00.000-04:00
2012-07-29T23:45:00.000Z
正如其他答案所述,显然谷歌正在向您提供自1970年年初以来在UTC / GMT(没有时区偏移)的Unix纪元以来的秒数。
除了使用java.util.Date/Calendar类之外,您还可以使用第三方开源Joda-Time库。
以下是一些示例源代码,向您展示如何将文本解析为带时区的日期时间。
// © 2013 Basil Bourque. This source code may be used freely forever by anyone taking full responsibility for doing so.
// import org.joda.time.*;
// import org.joda.time.format.*;
// Starting data.
String string = "1343605500";
String timeZoneName = "America/New_York";
// Convert string of seconds to number of milliseconds.
long millis = Long.parseLong( string ) * 1000 ; //
// Specify time zone rather than rely on default.
DateTimeZone timeZone = DateTimeZone.forID( timeZoneName );
// Instantiate DateTime object.
DateTime dateTime = new DateTime( millis, timeZone );
System.out.println( "dateTime: " + dateTime );
System.out.println( "dateTime in UTC/GMT: " + dateTime.toDateTime( DateTimeZone.UTC ) );
跑步时......
dateTime: 2012-07-29T19:45:00.000-04:00
dateTime in UTC/GMT: 2012-07-29T23:45:00.000Z
使用epoch中的计数时,必须注意: