Home > Backend Development > PHP Tutorial > php返回昨天的日期

php返回昨天的日期

WBOY
Release: 2016-06-23 14:09:40
Original
1389 people have browsed it

$today = (date("Y-m-d"))-1;
echo $today."
";
//昨天
$yesterday = date("Y-m-d", strtotime(date("Y-m-d"))-1);


$today = (date("Y-m-d"));
echo $today."
";
//昨天
$yesterday = date("Y-m-d", strtotime(date("Y-m-d"))-1);

一台可以 另一台不行。当时看返回的是昨天的,但等会又不是了


回复讨论(解决方案)

echo date('Y-m-d', strtotime("-1 day"));
Copy after login

$web['time_pos'] = 8; //时区

$now_time = gmdate('Y-m-d H:i:s', time() + $web['time_pos'] * 3600); //现在
$date_yeday = gmdate('Y-m-d', time() + $web['time_pos'] * 3600 - 24 * 3600); //昨天

可能是两台电脑的默认时区设置的问题
echo date_default_timezone_get();
看一下

echo date_default_timezone_get(); 

都返回:WIN7返回: UTC   win2003返回:PRC 

date_default_timezone_set('Asia/Shanghai');
echo date('Y-m-d', strtotime("-1 day"));

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template