How do I convert datetime to ISO 8601 in PHP

前端 未结 5 662
悲哀的现实
悲哀的现实 2020-11-27 12:58

How do I convert my time from 2010-12-30 23:21:46 to ISO 8601 date format? (-_-;)

5条回答
  •  忘掉有多难
    2020-11-27 13:39

    How to convert from ISO 8601 to unixtimestamp :

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

    How 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
    

    How to convert from unixtimestamp to ISO 8601 (GMT) :

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

    How 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
    

提交回复
热议问题