if-modified-since的PHP时间戳


PHP timestamp for if-modified-since with timezone

我已经将时间戳以以下格式存储在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)?

这对我有用:

$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())));