首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >时间格式说明(Google Directions API)

时间格式说明(Google Directions API)
EN

Stack Overflow用户
提问于 2013-03-26 00:56:20
回答 3查看 5.8K关注 0票数 1

我已经阅读了Google Directions API发出方向请求的文档。URL的示例如下所示

代码语言:javascript
复制
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

有人能解释一下这个时间格式吗?

谢谢。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-03-26 01:00:50

这是一个时间戳-自1970-01-01 00:00:00 UTCUnix epoch以来经过的秒数。如果需要“立即”格式,可以使用System.currentTimeMillis() / 1000,或者如果有Date对象,可以使用date.getTime() / 1000

票数 3
EN

Stack Overflow用户

发布于 2013-03-26 00:59:08

这是一个纪元unix时间戳(自1970年1月1日以来的秒数)。您可以通过以下方式创建日期

代码语言:javascript
复制
Date d = new Date(1343605500L);

或者使用http://www.epochconverter.com/

票数 1
EN

Stack Overflow用户

发布于 2013-12-20 15:39:39

Google文档中的缺陷

在谷歌上搜索这个特定的数字,就会找到this similar StackOverflow.com question这样的地方。这些页面让我得出结论,Google Directions API的文档存在缺陷。

你和其他人报告说1343605500 =2012年7月30日上午09:45在纽约。但这是不正确的。月份的日期和一天的小时都是错误的。

从1970年协调世界时/格林尼治标准时间开始的1343605500秒:

纽约的

  • 是协调世界时/格林尼治标准时间是2012-07-29T23:45:00.000Z

从数字中获取日期-时间

正如其他答案所述,显然Google向您提供的是自1970年年初Unix纪元以来的秒数,单位为UTC/GMT (无时区偏移)。

除了使用java.util.Date/Calendar类之外,您还可以使用第三方开源Joda-Time库。

下面是一些示例源代码,向您展示如何将文本解析为具有时区的日期-时间。

代码语言:javascript
复制
// © 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 ) );

运行…时

代码语言:javascript
复制
dateTime: 2012-07-29T19:45:00.000-04:00
dateTime in UTC/GMT: 2012-07-29T23:45:00.000Z

使用从纪元开始的计数时,必须注意以下事项:

秒,毫秒,nanoseconds) (秒,毫秒,

  • (秒,毫秒,秒

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15620486

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档