【问题标题】:PHP timestamp for if-modified-since with timezone带有时区的 if-modified-since 的 PHP 时间戳
【发布时间】:2015-12-18 22:37:07
【问题描述】:

我在 MySQL 中存储了以下格式的时间戳:

$if_modified_since = date('Y-m-d H:i:s');

时间戳是使用服务器的默认时区保存的,在我的例子中是EST。我需要发送带有if-modified-since 标头的CURL 请求。

curl_setopt($ch, CURLOPT_HTTPHEADER, array("If-Modified-Since: ".gmdate('D, d M Y H:i:s \G\M\T',$if_modified_since)));

我将EST 中的时间转换为GMT 的最佳方式是什么?还有一种方法可以通过检查服务器时区使其完全通用(而不仅仅是在EST 中进行硬编码)?

【问题讨论】:

    标签: php datetime timestamp if-modified-since


    【解决方案1】:

    这对我有用:

    $d = DateTime::createFromFormat('Y-m-d H:i:s', $if_modified_since, new DateTimeZone(ini_get('date.timezone'))); 
    curl_setopt($curl, CURLOPT_HTTPHEADER, array("If-Modified-Since: ".gmdate('D, d M Y H:i:s \G\M\T',$d->getTimestamp())));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-01
      • 2011-10-03
      • 2023-03-31
      • 2023-03-12
      • 2020-12-27
      • 2017-01-17
      • 2012-04-19
      相关资源
      最近更新 更多