简体   繁体   English

strtotime在php中无法正常工作以备将来使用?

[英]strtotime is not working proper in php for future date?

When i am converting date from dmY in Ymd format. 当我将日期格式从dmY转换为日期时。 i am facing some issues for it. 我面临一些问题。

example 19/08/1989 will convert into 1989/08/19 (it's correct), 示例19/08/1989将转换为1989/08/19(正确),

19/08/2059 will convert into 1970/01/01 (it's not correct) 19/08/2059将转换为1970/01/01(不正确)

$re_date = date('Y-m-d', strtotime($_POST['re_date']));

Help me please. 请帮帮我。 thanks in advance. 提前致谢。

The maximum date allowed is Tue, 19 Jan 2038 03:14:07 UTC on 32 bit system 在32位系统上,允许的最大日期为2038年1月19日(星期二)UTC

From the strotime docs : strotime文档

Note: 注意:

The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 UTC to Tue, 19 Jan 2038 03:14:07 UTC. 时间戳记的有效范围通常是从1901年12月13日星期五20:45:54 UTC到2038年1月19日星期二03:14:07 UTC。

If you want it to work for 32 bit system then try like this using DateTime : 如果您希望它在32位系统上运行,请尝试使用DateTime

$date = new DateTime($_POST['re_date']);

echo $date->format('Y-m-d');

better trick 更好的把戏

$str=explode('/',$_POST['re_date']);

$newdate = $str[2].'/'.$str[1].'/'.$str[0];

$ re_date = date('Y / m / d',strtotime($ _ POST ['re_date']));;

$date = $_POST['re_date'];
$date = str_replace("/", "-", $date);
$re_date = date('Y-m-d', strtotime($date));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM