簡體   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'));

要從ISO 8601轉換為unixtimestamp:

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

要從unixtimestamp轉換為ISO 8601(時區服務器):

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

要從unixtimestamp轉換為ISO 8601(GMT):

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

要從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