将ISO 8601转换为unixtimestamp

Cod*_*ler 34 php timestamp date date-format time-format

如何在PHP中将2012-01-18T11:45:00+01:00(ISO 8601)转换 为1326883500(unixtimestamp)?

k10*_*102 58

echo date("U",strtotime('2012-01-18T11:45:00+01:00'));
Run Code Online (Sandbox Code Playgroud)

  • 是需要的日期功能? (4认同)

Joh*_*ers 13

要从ISO 8601转换为unixtimestamp:

strtotime('2012-01-18T11:45:00+01:00');
// Output : 1326883500
Run Code Online (Sandbox Code Playgroud)

要从unixtimestamp转换为ISO 8601(时区服务器):

date_format(date_timestamp_set(new DateTime(), 1326883500), 'c');
// Output : 2012-01-18T11:45:00+01:00
Run Code Online (Sandbox Code Playgroud)

要从unixtimestamp转换为ISO 8601(GMT):

date_format(date_create('@'. 1326883500), 'c') . "\n";
// Output : 2012-01-18T10:45:00+00:00
Run Code Online (Sandbox Code Playgroud)

要从unixtimestamp转换为ISO 8601(自定义时区):

date_format(date_timestamp_set(new DateTime(), 1326883500)->setTimezone(new DateTimeZone('America/New_York')), 'c');
// Output : 2012-01-18T05:45:00-05:00
Run Code Online (Sandbox Code Playgroud)