我需要将给定的 GMT 日期和时间 (YYYY-MM-DD HH:MM) 转换为代表东海岸日期的字符串 YYYYMMDD。你觉得下面的代码可以吗?
$date='2011-11-07 04:30';
$date.='-4 hours';
$date=strftime('%Y-%m-%d %H:%M',strtotime($date));
$y=gmdate('Y');
$date2=date('Y-m-d 02:00',strtotime($y.'-03-01 second sunday'));
$date3=date('Y-m-d 02:00',strtotime($y.'-11-01 first sunday'));
if($date<=$date2||$date>=$date3) {
$date.='-1 hour';
$date=strftime('%Y-%m-%d %H:%M',strtotime($date));
}
$date=date('Ymd', strtotime($date));