Last active
April 28, 2017 10:15
-
-
Save lomboboo/dcc301026d95edd7e7a22b0e56a0ebca to your computer and use it in GitHub Desktop.
Przeformatowanie daty na polską, z poprawną odmianą dni i mieśiące
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 | |
date_default_timezone_set('Europe/Warsaw'); | |
function dateToPolishFormat($format,$timestamp=null){ | |
$to_convert = array( | |
'l'=>array('dat'=>'N','str'=>array('Poniedziałek','Wtorek','Środa','Czwartek','Piątek','Sobota','Niedziela')), | |
'F'=>array('dat'=>'n','str'=>array('styczeń','luty','marzec','kwiecień','maj','czerwiec','lipiec','sierpień','wrzesień','październik','listopad','grudzień')), | |
'f'=>array('dat'=>'n','str'=>array('stycznia','lutego','marca','kwietnia','maja','czerwca','lipca','sierpnia','września','października','listopada','grudnia')) | |
); | |
if ($pieces = preg_split('#[:/.\-, ]#', $format)){ | |
if ($timestamp === null) { $timestamp = time(); } | |
foreach ($pieces as $datepart){ | |
if (array_key_exists($datepart,$to_convert)){ | |
$replace[] = $to_convert[$datepart]['str'][(date($to_convert[$datepart]['dat'],$timestamp)-1)]; | |
}else{ | |
$replace[] = date($datepart,$timestamp); | |
} | |
} | |
$result = strtr($format,array_combine($pieces,$replace)); | |
return $result; | |
} | |
} | |
?> | |
// Usage | |
<?php echo dateV('l,\ j f Y', strtotime("now") ); ?> // znak \ dla poprawnego traktowania przecinku w formacie |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment