在查看php的mktime(http://php.net/manual/en/function.mktime.php)函数时发现php代码的时间最大值是2038年:
windows(32bit)下有效值是2038-01-19 03:14:07整型是2147483647
strtotime,time返回的是一个Unix时间戳,是个int值,这个值是有一个范围的,在php中,对于整形的定义没有有符号和无符号之分,虽然其字长和平台有关,但一般的最大值都是为231-1=2147483647
据说64位系统下没有这个问题
这里有个开源类解决该问题http://xwisdomhtml.com/dateclass.html
This Date Class library makes use of the ADODB Date library in
order to support timestamps before 1970 and after 2038. Here's a
short list of supported features:
*
Supports both php4 and php5.
* Handles
dates before and 1970 and afer 2038.
* Supports
over four different date input formats.
* Compatible
with existing php date functions (e.g date,strtotime,etc).
To start working with the Date class you will first need to
download and extract the dateclass.zip file to a folder. Copy the
files date.class.php and adodb_date.php to a folder on your website
or application. You will only need to include the file
date.class.php inside your PHP page.
Note: The ADODB Date Library is a standalone library and can
easily updated when a new version is available from the ADODB
website. This file is only included for convenience.
Example:
include_once "/includes/date.class.php";
$date = new Date("March 20, 2039 11:30 PM");
echo $date->format("d-M-Y");
You can also use the format() function to directly format date
value that's passed in as the second parameter.
Example:
$date = new Date();
echo $date->format("M d, Y","2079/12/20
12:30:23");
Supported Date Input Formats:
MM/DD/YYYY MM-DD-YYYY MM.DD.YYYY
DD/MM/YYYY DD-MM-YYYY DD.MM.YYYY
YYYY/MM/DD YYYY-MM-DD YYYY.MM.DD
MMM DD, YYYY DD MMM YYYY DD MMM YYYY HH:NN:SS AM/PM
本文转载自『北漂石头的博客』
http://www.niutian365.com/blog/
更多精彩内容,欢迎访问北漂石头的博客!