What happens is that in the index.ctp I have this:
<td><?= h($programacione->PrgHoraViaje->format('h:i')) ?></td>
It shows me the following:
7:30
I would like you to show me
7:30 **PM** ó **AM** *si fuese el caso*
The field HoraViaje is of type Time in MySQL
The CakePHP ORM returns an instance of Cake\I18n\Time for each date or time field in the database, so you can format it using its API.
The function
i18nFormat()
receives as a parameter an IntlDateFormatter or a date format string from ICUThe code:
will print
By the way the function
h()
is a wrapper for the PHP functionhtmlspecialchars()
, it is useful to use it when it is text that needs to be escaped, in this case I don't think it is needed.It is worth mentioning that it
format
receives the same parameters fromi18nFormat
it is correct to use both, the difference is that itformat
is from the classDate
that uses UTC for its calculations, while itTime
can receive a TimeZone.Another important difference is that it
format
receives a string with the format mentioned here , while iti18nFormat
receives the ICU format mentioned above.I just used this code:
And I get the time, but in 12-hour format:
Now, here is my question, which one should I use for good practices?