Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

date

php

strftime

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?

like image 794
Chaim Avatar asked May 09 '11 18:05

Chaim


People also ask

What can I use instead of Strftime in PHP?

The strftime is obsolete and DateTime::format() provide a quick replacement and IntlDateFormatter::format() provied a more sophisticated slution.

What is the use of Strftime function?

The strftime() function is used to convert date and time objects to their string representation. It takes one or more input of formatted code and returns the string representation. Returns : It returns the string representation of the date or time object.

What format is Strftime?

The strftime() method takes one or more format codes as an argument and returns a formatted string based on it. We imported datetime class from the datetime module. It's because the object of datetime class can access strftime() method. The datetime object containing current date and time is stored in now variable.

What is Strftime PHP?

strftime() function in PHP The strftime() function formats a local time/date according to locale settings. It returns a string formatted according to the given format string using the given timestamp or the current local time if no timestamp is given.


1 Answers

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.

like image 128
James C Avatar answered Oct 09 '22 16:10

James C