简体   繁体   English

将ISO 8601转换为unixtimestamp

[英]Convert ISO 8601 to unixtimestamp

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

echo date("U",strtotime('2012-01-18T11:45:00+01:00'));

To convert from ISO 8601 to unixtimestamp : 要从ISO 8601转换为unixtimestamp:

strtotime('2012-01-18T11:45:00+01:00');
// Output : 1326883500

To convert from unixtimestamp to ISO 8601 (timezone server) : 要从unixtimestamp转换为ISO 8601(时区服务器):

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

To convert from unixtimestamp to ISO 8601 (GMT) : 要从unixtimestamp转换为ISO 8601(GMT):

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

To convert from unixtimestamp to ISO 8601 (custom timezone) : 要从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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM