【问题标题】:Convert ISO 8601 to unixtimestamp将 ISO 8601 转换为 unix 时间戳
【发布时间】:2012-02-13 02:14:33
【问题描述】:

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

【问题讨论】:

    标签: php date timestamp date-format time-format


    【解决方案1】:
    echo date("U",strtotime('2012-01-18T11:45:00+01:00'));
    

    【讨论】:

    • 谢谢,不知道 strtotime 知道 ISO 日期
    • @Codler 在这种情况下没有。我想你可能想使用另一种格式的输入/输出
    【解决方案2】:

    从 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
    

    【讨论】:

    • 非常有用!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-11
    • 2011-04-16
    • 2011-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多