
Forum » » Demo » » strftime
Posté : 14 sept. 2023, 22:10 
function strf_time(string $time, string $pattern='eeee d MMMM y à HH:mm'): string {
global $locale;
$dateTimeObj = new DateTime($time, new DateTimeZone('Europe/Paris'));
$dateTimeObj->setTimezone(new \DateTimeZone('UTC'));
$datetime = IntlDateFormatter::formatObject(
$dateTimeObj,
$pattern,
$locale
);
return ucwords($datetime);
}
var_dump(strf_time($time)); // 'Dimanche 28 Février 2021 à 00:08'
var_dump(strf_time($time, 'y à HH:mm')); // '2021 à 00:08'
var_dump(strf_time('now')); // 'Jeudi 14 Septembre 2023 à 20:08'
var_dump(strf_time('now', 'y à HH:mm')); // '2023 à 20:08'
Cet article provient de NPDS REvolution 168
https://grottes-et-karsts.org/viewtopic.php?topic=11&forum=1