php 2038年,PHP 处理大于2038年以后的日期

在查看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/

更多精彩内容,欢迎访问北漂石头的博客!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值