PHP 5.2使用什么日期/时间函数 [英] What date/time functions to use for PHP 5.2

查看:85
本文介绍了PHP 5.2使用什么日期/时间函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DateTime,DateInterval等类在我正在使用的服务器上不可用(PHP 5.2)

我应该改用哪些功能?

解决方案

如果您查看 DateInterval ,您可以在方法名称下方看到特定功能所需的版本,例如

DateInterval :: createFromDateString
(PHP 5> = 5.3.0)

表示此方法可从PHP5.3开始使用.

就像其他答案中已经指出的那样,从5.2版开始,某些DateTime(但不是DateInterval)方法已经可以正常使用了.或者,您可以使用常规的日期函数.请注意,许多以date_timezone_为前缀的功能是DateTimeDateTimezone中它们各自的OOP对应物的别名,因此,如果您现在不能使用它们,则将无法使用它们.

如果您想要日期的OO库,请查看 PEAR_Date .

The DateTime, DateInterval etc. classes are not available at the server I am using (PHP 5.2)

Which functions should I use instead?

解决方案

If you look at the PHP Manual pages for DateTime and DateInterval, you can see which version is required for a specific function right below the method name, e.g.

DateInterval::createFromDateString
(PHP 5 >= 5.3.0)

indicates this method is available from PHP5.3 on.

Like already pointed out in other answers, some of the DateTime (but not DateInterval) methods are already regularly available as of 5.2. As an alternative, you can use the regular Date functions. Note that many of the functions prefixed with date_ and timezone_ are aliases for their respective OOP counterparts in DateTime and DateTimezone, so you will not be able to use them, if you cannot use them now.

If you want an OO lib for dates, have a look at Zend_Date or PEAR_Date.

这篇关于PHP 5.2使用什么日期/时间函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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