问题用PHP mktime()根据和/或PHP的日期() - 年之前,1901 - 64位根据、日期、问题、PHP

2023-09-08 10:32:34 作者:他说不让我输

我知道有一个问题,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?

我用code提到的here并确定我的主机运行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)

下面是code我使用到输入日期转换为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);

而code到再重新显示在基本格式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);

在code正常工作的日期> 1901年,然而,当$ Y&LT; 1901年,从date()函数的输出返回不正确的日期。

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

任何意见,以什么我做错了,如果使用mktime()根据和日期()函数这甚至有可能,和/或可能的解决方法将是极大的AP preciated。

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年 backwords限制 此外时间()日期()到2038年的未来是有限的,而日期时间不会有问题,将来无论是。 这里是一些阅读上的话题。

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.