php mktime() 和/或 php date() 问题 - 1901 年之前 - 64 位 [英] Issue with php mktime() and/or php date() - years prior to 1901 - 64-bit

查看:25
本文介绍了php mktime() 和/或 php date() 问题 - 1901 年之前 - 64 位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 php mktime()、32 位系统和年份 <1901 或 >2038 存在问题,但是,我的问题是,如果在 64 位系统上运行,这个问题是否仍然存在?

I understand there is an issue with php mktime(), 32bit systems, and years <1901 or >2038, however, my question is, does this issue still remain if operating on a 64 bit system?

我使用了提到的代码 此处 并确定我的主机运行的是 64 位系统.

I used the code mentioned here and determined my host is running a 64bit system.

我按照以下格式从用户输入中收集日期:

I am gathering dates from user inputs in the following format:

$m = 用户选择的月份(2 位数字);$d = 用户选择的日期(2 位数);$y = 用户选择的年份(4 位数字)

$m = user selected month (2 digits); $d = user selected day (2 digits); $y = user selected year (4 digits)

这是我用来将输入日期转换为 unix 时间戳的代码:

Here is the code I am using to convert the input date into a unix timestamp:

$npt_date=mktime(0,0,0,$m,$d,$y);

然后以基本格式xx-xx-xxxx重新显示日期的代码

And the code to then re-display the date in the basic format xx-xx-xxxx

$date_str=date('m-d-Y',$npt_date);

该代码适用于大于 1901 年的日期,但是,当 $y <1901,date() 函数的输出返回了错误的日期.

The code works fine for dates > 1901, however, when $y < 1901, the output from the date() function returns the incorrect date.

任何关于我做错了什么的建议,如果这甚至可以使用 mktime() 和 date() 函数和/或可能的解决方法,将不胜感激.

Any advice as to what I am doing wrong, if this is even possible using the mktime() and date() functions, and/or possible workaround would be greatly appreciated.

提前致谢.

推荐答案

开始使用 DateTime.到 1000 年,它只是有限的反向词.
此外,time()date() 在未来受到 2038 的限制,而 DateTime 未来也不会出现问题.
这是有关该主题的一些阅读资料.

It might be a good idea to start using DateTime. It's only limited backwords by the year 1000.
Also time() and date() are limited by 2038 in the future, whereas DateTime won't have problem with the future either.
Here is some reading on the topic.

这篇关于php mktime() 和/或 php date() 问题 - 1901 年之前 - 64 位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆