Convert ISO 8601 to unixtimestamp

前端 未结 2 1675
长情又很酷
长情又很酷 2020-12-28 14:09

How can I convert 2012-01-18T11:45:00+01:00 (ISO 8601) to 1326883500 (unixtimestamp) in PHP?

相关标签:
2条回答
  • 2020-12-28 14:31
    echo date("U",strtotime('2012-01-18T11:45:00+01:00'));
    
    0 讨论(0)
  • 2020-12-28 14:36

    To convert from ISO 8601 to unixtimestamp :

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

    To convert from unixtimestamp to ISO 8601 (timezone server) :

    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) :

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

    To convert from unixtimestamp to ISO 8601 (custom timezone) :

    date_format(date_timestamp_set(new DateTime(), 1326883500)->setTimezone(new DateTimeZone('America/New_York')), 'c');
    // Output : 2012-01-18T05:45:00-05:00
    
    0 讨论(0)
提交回复
热议问题