Last active
December 22, 2015 10:59
-
-
Save tyx/6462392 to your computer and use it in GitHub Desktop.
This file contains 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 | |
function getFormatter($dateFormat = 'medium', $timeFormat = 'medium', $locale = null, $timezone = null, $format = null) | |
{ | |
$formatValues = array( | |
'none' => \IntlDateFormatter::NONE, | |
'short' => \IntlDateFormatter::SHORT, | |
'medium' => \IntlDateFormatter::MEDIUM, | |
'long' => \IntlDateFormatter::LONG, | |
'full' => \IntlDateFormatter::FULL, | |
); | |
return \IntlDateFormatter::create( | |
$locale !== null ? $locale : \Locale::getDefault(), | |
$formatValues[$dateFormat], | |
$formatValues[$timeFormat], | |
$timezone !== null ? $timezone : 'UTC', | |
\IntlDateFormatter::GREGORIAN, | |
$format | |
); | |
} | |
$start = new DateTime('first day of previous month 00:00:00', new DateTimeZone('Europe/paris')); | |
$start->setTimezone(new DateTimeZone('UTC')); | |
$end = clone $start; | |
$formatter = getFormatter('full', 'medium', 'fr', 'Europe/Paris'); | |
echo $formatter->format($end); |
This file contains 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 | |
function getFormatter($dateFormat = 'medium', $timeFormat = 'medium', $locale = null, $timezone = null, $format = null) | |
{ | |
$formatValues = array( | |
'none' => \IntlDateFormatter::NONE, | |
'short' => \IntlDateFormatter::SHORT, | |
'medium' => \IntlDateFormatter::MEDIUM, | |
'long' => \IntlDateFormatter::LONG, | |
'full' => \IntlDateFormatter::FULL, | |
); | |
return \IntlDateFormatter::create( | |
$locale !== null ? $locale : \Locale::getDefault(), | |
$formatValues[$dateFormat], | |
$formatValues[$timeFormat], | |
$timezone !== null ? $timezone : 'UTC', | |
\IntlDateFormatter::GREGORIAN, | |
$format | |
); | |
} | |
$start = new DateTime('first day of previous month', new DateTimeZone('Europe/paris')); | |
$start = new DateTime($start->format('Y-m-d 00:00:00'), new DateTimeZone('Europe/paris')); | |
$start->setTimezone(new DateTimeZone('UTC')); | |
$end = clone $start; | |
$formatter = getFormatter('full', 'medium', 'fr', 'Europe/Paris'); | |
echo $formatter->format($end); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment