This is the code I use to get the date (in spanish):
$fecha = strftime("%d de %B, %Y, a las %l:%M %p");
and I get:
27 de julio, 2011, a las 7:10
So the question is, where is my PM (or AM)?
My application is running on Linux.
Replacements. For locale-aware date/time formatting, use IntlDateFormatter::format (requires Intl extension). In a real-life and ideal use case, the IntlDateFormatter object is instantiated once based on the user's locale information, and the object instance can is used whenever necessary.
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.
Well,, the php manual says
Not all conversion specifiers may be supported by your C library, in which case they will not be supported by PHP's strftime(). Additionally, not all platforms support negative timestamps, so your date
This could be your problem. In that case you could do something like this to get the AM/PM:
$time = time();
$fecha = strftime("%d de %B, %Y, a las %l:%M ", $time).(($time%86400) < 43200 ? 'AM' : 'PM');
EDIT:
This answer is assuming you want a UTC time string (if you want another timezone, you should also include the timezone in the string if you are storing it or sending it anywhere), and that your php.ini has date.timezone
set to UTC
. If you are not using UTC, you should compute an offset. See @Soylent17's answer.
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