From a PR on May 9
I think the distinction between timezone and locale may be conflated here, I don’t want to create unnecessary work – it just looks like all we really accomplish is swapping between ‘m/d/y’ or ‘d/m/y’, which is still not fulling achieving localized formatting. For example, some locales use different separators, or have preferences on the number of digits in different places, leading zeroes, 12 or 24 hour time, etc.
IntlDateFormatter
accomplishes all of this pretty handily.
<?php
$timezones = [
'LA (USA)' => 'America/Los_Angeles',
'New York (USA)' => 'America/New_York',
'Paris (FR)' => 'Europe/Paris',
'Brisbane (Aus)' => 'Australia/Brisbane',
];
$locales = [
'American' => 'en-US',
'Australian' => 'en-AU',
'British' =>'en-UK',
'Canadian' => 'en-CA',
'French Canadian' => 'fr-CA',
'French' => 'fr-FR',
'Japanese' => 'ja-JP',
];
$absoluteDate = new DateTimeImmutable('2024-12-06T03:02:01.123456Z');
foreach ($timezones as $place => $tzName) {
echo "\n\n7 people in {$place}, each looking at their computer to find the time and date:";
foreach ($locales as $nationality => $locale) {
$fullFormatter = new IntlDateFormatter(
$locale,
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
new DateTimeZone($tzName)
);
$shortFormatter = new IntlDateFormatter(
$locale,
IntlDateFormatter::SHORT,
IntlDateFormatter::SHORT,
new DateTimeZone($tzName)
);
$shortDateOnlyFormatter = new IntlDateFormatter(
$locale,
IntlDateFormatter::SHORT,
IntlDateFormatter::NONE,
new DateTimeZone($tzName)
);
echo "\n
The {$nationality} one sees:
- Full: {$fullFormatter->format($absoluteDate)}
- Short: {$shortFormatter->format($absoluteDate)}
- Short date: {$shortDateOnlyFormatter->format($absoluteDate)}";
}
}
OUTPUT:
7 people in LA (USA), each looking at their computer to find the time and date:
The American one sees:
- Full: Thursday, December 5, 2024 at 7:02:01 PM Pacific Standard Time
- Short: 12/5/24, 7:02 PM
- Short date: 12/5/24
The Australian one sees:
- Full: Thursday, 5 December 2024 at 7:02:01 pm Pacific Standard Time
- Short: 5/12/24, 7:02 pm
- Short date: 5/12/24
The British one sees:
- Full: Thursday, December 5, 2024 at 7:02:01 PM Pacific Standard Time
- Short: 12/5/24, 7:02 PM
- Short date: 12/5/24
The Canadian one sees:
- Full: Thursday, December 5, 2024 at 7:02:01 p.m. Pacific Standard Time
- Short: 2024-12-05, 7:02 p.m.
- Short date: 2024-12-05
The French Canadian one sees:
- Full: jeudi 5 décembre 2024 à 19 h 02 min 01 s heure normale du Pacifique
- Short: 24-12-05 19 h 02
- Short date: 24-12-05
The French one sees:
- Full: jeudi 5 décembre 2024 à 19:02:01 heure normale du Pacifique nord-américain
- Short: 05/12/2024 19:02
- Short date: 05/12/2024
The Japanese one sees:
- Full: 2024年12月5日木曜日 19時02分01秒 アメリカ太平洋標準時
- Short: 2024/12/05 19:02
- Short date: 2024/12/05
7 people in New York (USA), each looking at their computer to find the time and date:
The American one sees:
- Full: Thursday, December 5, 2024 at 10:02:01 PM Eastern Standard Time
- Short: 12/5/24, 10:02 PM
- Short date: 12/5/24
The Australian one sees:
- Full: Thursday, 5 December 2024 at 10:02:01 pm Eastern Standard Time
- Short: 5/12/24, 10:02 pm
- Short date: 5/12/24
The British one sees:
- Full: Thursday, December 5, 2024 at 10:02:01 PM Eastern Standard Time
- Short: 12/5/24, 10:02 PM
- Short date: 12/5/24
The Canadian one sees:
- Full: Thursday, December 5, 2024 at 10:02:01 p.m. Eastern Standard Time
- Short: 2024-12-05, 10:02 p.m.
- Short date: 2024-12-05
The French Canadian one sees:
- Full: jeudi 5 décembre 2024 à 22 h 02 min 01 s heure normale de l’Est
- Short: 24-12-05 22 h 02
- Short date: 24-12-05
The French one sees:
- Full: jeudi 5 décembre 2024 à 22:02:01 heure normale de l’Est nord-américain
- Short: 05/12/2024 22:02
- Short date: 05/12/2024
The Japanese one sees:
- Full: 2024年12月5日木曜日 22時02分01秒 アメリカ東部標準時
- Short: 2024/12/05 22:02
- Short date: 2024/12/05
7 people in Paris (FR), each looking at their computer to find the time and date:
The American one sees:
- Full: Friday, December 6, 2024 at 4:02:01 AM Central European Standard Time
- Short: 12/6/24, 4:02 AM
- Short date: 12/6/24
The Australian one sees:
- Full: Friday, 6 December 2024 at 4:02:01 am Central European Standard Time
- Short: 6/12/24, 4:02 am
- Short date: 6/12/24
The British one sees:
- Full: Friday, December 6, 2024 at 4:02:01 AM Central European Standard Time
- Short: 12/6/24, 4:02 AM
- Short date: 12/6/24
The Canadian one sees:
- Full: Friday, December 6, 2024 at 4:02:01 a.m. Central European Standard Time
- Short: 2024-12-06, 4:02 a.m.
- Short date: 2024-12-06
The French Canadian one sees:
- Full: vendredi 6 décembre 2024 à 04 h 02 min 01 s heure normale d’Europe centrale
- Short: 24-12-06 04 h 02
- Short date: 24-12-06
The French one sees:
- Full: vendredi 6 décembre 2024 à 04:02:01 heure normale d’Europe centrale
- Short: 06/12/2024 04:02
- Short date: 06/12/2024
The Japanese one sees:
- Full: 2024年12月6日金曜日 4時02分01秒 中央ヨーロッパ標準時
- Short: 2024/12/06 4:02
- Short date: 2024/12/06
7 people in Brisbane (Aus), each looking at their computer to find the time and date:
The American one sees:
- Full: Friday, December 6, 2024 at 1:02:01 PM Australian Eastern Standard Time
- Short: 12/6/24, 1:02 PM
- Short date: 12/6/24
The Australian one sees:
- Full: Friday, 6 December 2024 at 1:02:01 pm Australian Eastern Standard Time
- Short: 6/12/24, 1:02 pm
- Short date: 6/12/24
The British one sees:
- Full: Friday, December 6, 2024 at 1:02:01 PM Australian Eastern Standard Time
- Short: 12/6/24, 1:02 PM
- Short date: 12/6/24
The Canadian one sees:
- Full: Friday, December 6, 2024 at 1:02:01 p.m. Australian Eastern Standard Time
- Short: 2024-12-06, 1:02 p.m.
- Short date: 2024-12-06
The French Canadian one sees:
- Full: vendredi 6 décembre 2024 à 13 h 02 min 01 s heure normale de l’Est de l’Australie
- Short: 24-12-06 13 h 02
- Short date: 24-12-06
The French one sees:
- Full: vendredi 6 décembre 2024 à 13:02:01 heure normale de l’Est de l’Australie
- Short: 06/12/2024 13:02
- Short date: 06/12/2024
The Japanese one sees:
- Full: 2024年12月6日金曜日 13時02分01秒 オーストラリア東部標準時
- Short: 2024/12/06 13:02
- Short date: 2024/12/06