使用PHP以太平洋标准时间(西海岸)时间显示当前时间最简单的方法是什么?
发布于 2010-06-16 02:59:13
好吧,最简单的可能是:
date_default_timezone_set('America/Los_Angeles');
echo date('Y-m-d');看一看supported timezones,找到一个适合您需要的。
发布于 2010-06-16 03:57:44
让我们尝试一个使用PHP的现代日期处理的解决方案。此示例需要PHP 5.2或更高版本。
// Right now it's about four minutes before 1 PM, PST.
$pst = new DateTimeZone('America/Los_Angeles');
$three_hours_ago = new DateTime('-3 hours', $pst); // first argument uses strtotime parsing
echo $three_hours_ago->format('Y-m-d H:i:s'); // "2010-06-15 09:56:36"发布于 2016-05-04 03:16:21
如果您正在使用或有权访问Carbon,您可以这样做:
$timezone = 'America/Los_Angeles';
$now = Carbon::now()->tz($timezone)->toDateTimeString();
echo $now;https://stackoverflow.com/questions/3048162
复制相似问题