PHP strtotime()不输出任何内容 [英] PHP strtotime() outputs nothing

查看:439
本文介绍了PHP strtotime()不输出任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的PHP代码:

echo '<br />1. '.$w_time_no;
echo '<br />2. '.strtotime($w_time_no);
echo '<br />3. '.date('G:i', strtotime($w_time_no));

这就是我所得到的:

1. 0000-00-00 22:00:00
2.
3. 2:00

为什么strtotime()本身没有输出?服务器设置有问题吗?服务器:Apache / 2.2.11(Win32),PHP 5.2.10,MySQL客户端版本:5.0.51a。

Why strtotime() outputs nothing by itself? Is there something wrong with server settings? Server: Apache/2.2.11 (Win32), PHP 5.2.10, MySQL client version: 5.0.51a.

推荐答案

code> strtotime 不会输出任何东西,btw:如果发生错误,它返回 false 请参阅手册

strtotime doesn't "output" anything, btw : it returns false in case of an error ; see the manual :


返回值

返回成功时间戳,否则返回FALSE
。在PHP 5.1.0之前,这个
函数会在失败时返回-1。

Returns a timestamp on success, FALSE otherwise. Previous to PHP 5.1.0, this function would return -1 on failure.

什么不输出什么是 echo false 被视为一个空字符串,没有任何输出。

What doesn't output anything is echo : false is considered as an empty string, and nothing get outputed.

strtotime的文档还给出了日期的有效范围:

strtotime's documentation also gives the valid range for dates :


注意:时间戳的有效范围
通常是从星期五,13十二月1901
20:45:54 UTC到星期二,20一月2038
03:14:07 UTC。 (这些日期是
,对应于32位签名的
整数的最小值和
最大值。)此外,并非所有
平台都支持负时间戳,
因此,您的日期范围可能是
限于不早于Unix
纪元。这意味着例如在1970年1月1日之前的日期
将不能在
Windows,一些Linux发行版和
上执行其他一些操作系统。 PHP
5.1.0和更新的版本克服了这个限制。

Note: The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 UTC to Tue, 19 Jan 2038 03:14:07 UTC. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.) Additionally, not all platforms support negative timestamps, therefore your date range may be limited to no earlier than the Unix epoch. This means that e.g. dates prior to Jan 1, 1970 will not work on Windows, some Linux distributions, and a few other operating systems. PHP 5.1.0 and newer versions overcome this limitation though.

'0000-00- 00'不在此范围内,因此不被视为有效日期;因此 false 返回值。

'0000-00-00' is outside of this range, so it's not considered a valid date ; hence the false return value.



作为旁注,要真正知道内部是什么一个变量,您可以使用 var_dump

作为一个bnus,与 Xdebug 一起使用,它会给你一个很好的输出; - )


As a sidenote, to really know what's inside a variable, you can use var_dump.
As a bnus, used with Xdebug, it'll get you a nice-formated output ;-)

这篇关于PHP strtotime()不输出任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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