PHP: strftime(), date() or DateTime, Which is better?

这一生的挚爱 提交于 2019-12-04 10:01:32

问题


I am curious to know if there is any advantage in PHP of using strftime() over date() or vice versa.

A class I downloaded used the strftime(). However, since it does not support all time formats on some systems, I want to change it to use date() instead. I was wondering if there are any major differances or advantages in using one over the other.

What about the fact that strftime() only supports date formats that are supported by that servers c library? Does date() have any similar restrictions?


回答1:


I think you'll find date() is more widely used than strftime()

date() is only able to return month/day names in English and won't be able to give you translations for other languages.

The performance implications should be negligible.

If you decide to go the date route I'd really recommend using DateTime which makes most date and time related operations easier than using the original procedural functions.




回答2:


is any advantage in PHP of using strftime() over date()

From the date manual page:

To format dates in other languages, you should use the setlocale() and strftime() functions instead of date().



来源:https://stackoverflow.com/questions/5941121/php-strftime-date-or-datetime-which-is-better

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!