Issue
this might be a simple question but honestly the cookbook's documentation on this is quite scarce and I can't find anything online.
I've got a database that is storing the time in timestamp format, and when I retrieve it I'm trying to show in a different format. I've got everything to show as I want to apart of the day.
date->i18nFormat('dd-MM-yyyy H:mm:ss')
See, I'm trying to show nd / rd / th next to the day number. All I can find is jS but when I use it nothing shows up.
Is there any other way? Thanks.
Solution
jS
is a standard PHP date format pattern, but Time::i18nFormat()
is for localizable dates, and it uses the INTL date formatter, which makes use of ICU formatting patterns, which have no support for ordinals (probably because most languages don't have them).
So if you don't actually need to create localizable output, use the regular PHP date formatter via the format()
method inherited from \DateTime
/ \DateTimeImmutable
:
$date->format('F jS, Y H:i:s');
See also
- Cookbook > Date and Time > Formatting
- PHP Manual > Function Reference > Date and Time Related Extensions > Date/Time > DateTimeInterface
Answered By - ndm
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.