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?
The strftime is obsolete and DateTime::format() provide a quick replacement and IntlDateFormatter::format() provied a more sophisticated slution.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With