-
-
Save A973C/33d01866fae4497a3400e57b18e35b6e to your computer and use it in GitHub Desktop.
PHP DateTime in french language
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class DateTimeFrench extends DateTime { | |
public function format($format='j M Y'){ | |
$days_full = array( | |
'Monday' => 'Lundi', | |
'Tuesday' => 'Mardi', | |
'Wednesday' => 'Mercredi', | |
'Thursday' => 'Jeudi', | |
'Friday' => 'Vendredi', | |
'Saturday' => 'Samedi', | |
'Sunday' => 'Dimanche' | |
); | |
$days_small = array( | |
'Mon' => 'Lun', | |
'Tue' => 'Mar', | |
'Wed' => 'Mer', | |
'Thu' => 'Jeu', | |
'Fri' => 'Ven', | |
'Sat' => 'Sam', | |
'Sun' => 'Dim' | |
); | |
$months_full = array( | |
'January' => 'Janvier', | |
'February' => 'Février', | |
'March' => 'Mars', | |
'April' => 'Avril', | |
'May' => 'Mai', | |
'June' => 'Juin', | |
'July' => 'Juillet', | |
'August' => 'Août', | |
'September' => 'Septembre', | |
'October' => 'Octobre', | |
'November' => 'Novembre', | |
'December' => 'Décembre' | |
); | |
$months_small = array( | |
'Feb' => 'Fév', | |
'Apr' => 'Avr', | |
'May' => 'Mai', | |
'Jun' => 'Juin', | |
'Jul' => 'Juil', | |
'Aug' => 'Août', | |
'Dec' => 'Déc' | |
); | |
$display = parent::format($format); | |
if( strstr($format, 'l') ){ | |
$display = str_replace(array_keys($days_full), array_values($days_full), $display); | |
} | |
if( strstr($format, 'D') ){ | |
$display = str_replace(array_keys($days_small), array_values($days_small), $display); | |
} | |
if( strstr($format, 'F') ){ | |
$display = str_replace(array_keys($months_full), array_values($months_full), $display); | |
} | |
if( strstr($format, 'M') ){ | |
$display = str_replace(array_keys($months_small), array_values($months_small), $display); | |
} | |
return $display; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$dt = new DateTimeFrench('2018-02-02 20:30:00'); | |
echo $dt->format('l j F Y à H\hi'); // Vendredi 2 Février 2018 à 20h30 | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment