Skip to content

Instantly share code, notes, and snippets.

@CanNuhlar
Last active July 29, 2018 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CanNuhlar/75a9f9642c547fb2d5c7b3e012da2388 to your computer and use it in GitHub Desktop.
Save CanNuhlar/75a9f9642c547fb2d5c7b3e012da2388 to your computer and use it in GitHub Desktop.
Localize date from an English default string to Turkish using PHP
<?
function localize_date($date){
$days = array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun");
$months = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
$daysLocal = array("Pazartesi", "Salı", "Çarşamba", "Perşembe", "Cuma", "Cumartesi", "Pazar");
$monthsLocal = array("Ocak", "Şubat", "Mart", "Nisan", "Mayıs", "Haziran", "Temmuz", "Ağustos", "Eylül", "Ekim", "Kasım", "Aralık");
foreach($days as $key => $day){
$date = str_replace($day, $daysLocal[$key], $date);
}
foreach($months as $key => $month){
$date = str_replace($month, $monthsLocal[$key], $date);
}
return $date;
}
?>
//localize_date("Tue, 12 Apr 2016 12:32:49 +0000") returns
//Salı, 12 Nisan 2016 12:32:49 +0000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment