日期限制PHP [英] Date Limitation PHP

查看:87
本文介绍了日期限制PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将时间与给定的字符串日期&时间。我只是试着用下面的例子。

I am trying to separate time from the given string date & time. I simply tried with following example.

$time = '2014-01-20 10:45:45';
echo '<br>'.$finalTime = date("H:i:s",strtotime($time));
echo '<br>'.$date = date("d F Y",strtotime($time));

我正确的日期和时间。

10:45:45
20 January 2014

但是当我尝试使用给定的字符串时,没有正确的结果。

But when I tried with given string, no correct result.

$time = '1899-12-30 19:30:00';
echo '<br>'.$finalTime = date("H:i:s",strtotime($time));
echo '<br>'.$date = date("d F Y",strtotime($time));

PHP总是让我收到以下结果。

PHP is always returning me following result.

00:00:00
01 January 1970

我不知道日期功能是否有限制,是不是返回1899.是这样吗?

I am not sure whether is there any limitation on date function that is not returning 1899. Is that so?

推荐答案

使用 DateTime DateTime :: format()

$time = '1899-12-30 19:30:00';
$dt = new DateTime($time);
echo $dt->format('d F Y H:i:s');

工作示例: http://3v4l.org/fM22Z

strtotime() 方法受到Unix epoch的限制,即1970年1月1日。

The strtotime() method is limited by the Unix epoch, which is Jan 1, 1970.

更新:如下面的标记注释所示,您的代码可以一直运行到1901年(作为负时间戳),请参阅这里: http://3v4l.org/CSJte

Update: As Mark comments below, your code would work all the way back to 1901 (as a negative timestamp), see here: http://3v4l.org/CSJte

这篇关于日期限制PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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