Skip to content

Instantly share code, notes, and snippets.

@tyx
Last active December 22, 2015 10:59
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 tyx/6462392 to your computer and use it in GitHub Desktop.
Save tyx/6462392 to your computer and use it in GitHub Desktop.
<?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);
<?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