Facebook创建日期使用的时间格式是什么?

13

你好,我正在使用Facebook Graph API,需要获取一个群组中所有帖子的信息。我已经完成了这个任务,并看到了 [created_date'] => '2013-01-25T00:11:02+0000' 这个日期和时间代表什么?我的意思是,我知道2013-01-25 是日期,00:11:02 是时间,但是 T+0000 代表什么?

顺便问一下,Facebook的服务器在哪里?我应该使用哪个时间戳来匹配Facebook的时间?

谢谢。


4
准确来说,它是ISO 8601 - Ja͢ck
3个回答

29

T表示时间,而+0000是时区偏移量。Facebook使用本地化的时区。您可以通过在Graph API调用中添加参数date_format=U来请求Unix时间戳而不是字符串。

更多信息请参见此链接


2
@HighParkCoder 什么是本地化时区意味着什么? - Prajwol Onta

13
日期格式被称为ISO 8601。字母T用于明确地分隔日期和时间,+0000用于表示时区偏移量,此处为GMT或UTC。
话虽如此,你通常不需要太担心实际内容;相反,你应该知道如何处理它们。要使用这样的日期,你可以使用strtotime()将其转换为时间戳:
$ts = strtotime('2013-01-25T00:11:02+0000');

要将时间戳转换回字符串表示形式,您可以简单地使用预定义的日期常量DATE_ISO8601gmdate()函数。
echo gmdate(DATE_ISO8601, $ts);

或者,使用DateTime
// import date
$d = DateTime::createFromFormat(DateTime::ISO8601, '2013-01-25T00:11:02+0000');

// export date
echo $dd->format(DateTime::ISO8601), PHP_EOL;

附注: DateTime::createFromFormat() 自 5.3.0 版本开始可用。 - Raptor

5
这是一个标准格式,具体参考 ISO 8601
尽管我不太喜欢引用它,但http://www.w3schools.com/schema/schema_dtypes_date.asp提供了一个很好的“人类可理解”的解释:

The dateTime is specified in the following form "YYYY-MM-DDThh:mm:ss" where:

YYYY indicates the year
MM indicates the month
DD indicates the day
T indicates the start of the required time section
hh indicates the hour
mm indicates the minute
ss indicates the second

To specify a time zone, you can either enter a dateTime in UTC time by adding a "Z" behind the time - like this:

2002-05-30T09:30:10Z

or you can specify an offset from the UTC time by adding a positive or negative time behind the time - like this:

2002-05-30T09:30:10-06:00

or

2002-05-30T09:30:10+06:00

因此,在您的情况下,+0000 表示与 UTC 的时间偏移量为 0。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接