Translate time (p.m. or a.m.)

I would like to translate time field

in French: 18:00
in English: 6:00 p.m


in French: 9:00
in English: 9:00 a.m.

I already translated dates from French (d.m.Y) to English (m.d.Y) with languages files, but in this case, I have to detect wich is after or before 12:00 and I don’t think that languages files could help me. Do you know a trick for that?

The same approach should work for times: See PHP date functions:, by defining the time string in the language files.

Oh yes thank you ! I didn’t know about any php native function about that.

<?= $page->horaires()->toDate(t('heure')) ?>

.en file: 'heure' => 'h.i a',
.fr file: 'heure' => 'G.i',

I thought the correct way to write the time in English was with a dot between a and m and between p and m. This is not the case here. But I think it should be fine


Check out PHP’s international date formatter.

Actually, the “correct” way even in English is to use the 24-Hour format. It is recommended in ISO 8601 (which is also a British Standard) and accepted worldwide, because it is unambiguous and easier to understand.

Good to know ! If anyone else is using the other way of writing the time (with am and pm) for some other reasons, I would be interested to know why. Maybe a way to respect some typographical codes in certain regions of the world?

I mean standards are standards but old habits die hard :blush: