如何从数组中获取的时间值中添加8小时?
来自:
$time = "Thu Jan 12 02:01:17 +0000 2012";
收件人:
$time = "Thu Jan 12 10:01:17 +0000 2012";
有几种方法可以做到这一点,简单且不太准确的方法:
echo date('+8 hours', strtotime($time));
使用DateTime
类的更高级方法:
//create DateTime instance
$date = new DateTime($time);
//set custom timezone
$date->setTimezone(new DateTimeZone('Europe/London'));
//add 8 hours
$date->modify('+8 hours');
//print formatted datetime string
print $date->format('D M d H:i:s O Y');
您可以使用DateTime类:
$time = new DateTime("Thu Jan 12 02:01:17 +0000 2012");
echo $time->modify("+8 hours")->format("D M d H:i:s O Y");
请参阅:http://www.php.net/manual/en/class.datetime.php它还可以进行时区操作等。
date_default_timezone_set('UTC');
$time = "Thu Jan 12 02:01:17 +0000 2012";
echo date('D M d H:i:s +0000 Y', strtotime($time.' +8 hours'))."'n";
<?php
$hours= date("D M d H:i:s +0000 Y",strtotime("Thu Jan 12 02:01:17 +0000 2012 +8 hours"));
echo $hours;
?>
演示