本文整理汇总了PHP中IntlDateFormatter::create方法的典型用法代码示例。如果您正苦于以下问题:PHP IntlDateFormatter::create方法的具体用法?PHP IntlDateFormatter::create怎么用?PHP IntlDateFormatter::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IntlDateFormatter
的用法示例。
在下文中一共展示了IntlDateFormatter::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: twig_localized_date_filter
function twig_localized_date_filter(Twig_Environment $env, $date, $dateFormat = 'medium', $timeFormat = 'medium', $locale = null, $timezone = null, $format = null, $calendar = 'gregorian')
{
$date = twig_date_converter($env, $date, $timezone);
$formatValues = array('none' => IntlDateFormatter::NONE, 'short' => IntlDateFormatter::SHORT, 'medium' => IntlDateFormatter::MEDIUM, 'long' => IntlDateFormatter::LONG, 'full' => IntlDateFormatter::FULL);
$formatter = IntlDateFormatter::create($locale, $formatValues[$dateFormat], $formatValues[$timeFormat], PHP_VERSION_ID >= 50500 ? $date->getTimezone() : $date->getTimezone()->getName(), 'gregorian' === $calendar ? IntlDateFormatter::GREGORIAN : IntlDateFormatter::TRADITIONAL, $format);
return $formatter->format($date->getTimestamp());
}
示例2: twig_localized_date_filter
function twig_localized_date_filter(Twig_Environment $env, $date, $dateFormat = 'medium', $timeFormat = 'medium', $locale = null, $timezone = null, $format = null)
{
$date = twig_date_converter($env, $date, $timezone);
$formatValues = array('none' => IntlDateFormatter::NONE, 'short' => IntlDateFormatter::SHORT, 'medium' => IntlDateFormatter::MEDIUM, 'long' => IntlDateFormatter::LONG, 'full' => IntlDateFormatter::FULL);
$formatter = IntlDateFormatter::create($locale, $formatValues[$dateFormat], $formatValues[$timeFormat], $date->getTimezone()->getName(), IntlDateFormatter::GREGORIAN, $format);
return $formatter->format($date->getTimestamp());
}
示例3: getAvailableTimes
public function getAvailableTimes()
{
$holidays = $this->manager->getRepository(Holiday::class)->findAll();
$result = array();
$formatter = \IntlDateFormatter::create('fr_FR', \IntlDateFormatter::FULL, \IntlDateFormatter::NONE);
$current = new \DateTime('+2 days');
$max = new \DateTime('+3 weeks');
while ($current < $max) {
if ($this->isClosed($current, $holidays)) {
continue;
}
$day = $current->format('N');
$date = $formatter->format($current);
if ($day == 6 || $day == 7) {
$hours = $this->weekEndHours;
} else {
$hours = $this->workDayHours;
}
$vals = array_map(function ($val) use($date) {
return $date . ' // ' . $val;
}, $hours);
$result[$date] = array_combine($vals, $vals);
$current->modify('+1 day');
}
return $result;
}
示例4: buildView
/**
* {@inheritdoc}
*/
public function buildView(SearchFieldView $view, FieldConfigInterface $config, array $options)
{
if (is_string($options['format'])) {
$format = $options['format'];
} else {
$format = \IntlDateFormatter::create(\Locale::getDefault(), is_int($options['format']) ? $options['format'] : self::DEFAULT_FORMAT, \IntlDateFormatter::NONE, null, \IntlDateFormatter::GREGORIAN)->getPattern();
}
$view->vars['format'] = $format;
}
示例5: localedate
public function localedate($date, $dateFormat = 'medium', $timeFormat = 'medium', $locale = null)
{
$formatValues = array('none' => \IntlDateFormatter::NONE, 'short' => \IntlDateFormatter::SHORT, 'medium' => \IntlDateFormatter::MEDIUM, 'long' => \IntlDateFormatter::LONG, 'full' => \IntlDateFormatter::FULL);
$formatter = \IntlDateFormatter::create($locale != null ? $locale : $this->translator->getLocale(), $formatValues[$dateFormat], $formatValues[$timeFormat]);
if ($date instanceof \DateTime) {
return $formatter->format($date);
}
return $formatter->format(new \DateTime($date));
}
示例6: localeDateFilter
/**
* A date formatting filter for Twig, renders the date using the specified parameters.
*
* @param mixed $date Unix timestamp to format
* @param string $locale The locale
* @param string $dateType The date type
* @param string $timeType The time type
* @param string $pattern The pattern to use
*
* @return string
*/
public static function localeDateFilter($date, $locale = "nl", $dateType = 'medium', $timeType = 'none', $pattern = null)
{
$values = array('none' => DateFormatter::NONE, 'short' => DateFormatter::SHORT, 'medium' => DateFormatter::MEDIUM, 'long' => DateFormatter::LONG, 'full' => DateFormatter::FULL);
if (is_null($pattern)) {
$dateFormatter = DateFormatter::create($locale, $values[$dateType], $values[$timeType], 'Europe/Brussels');
} else {
$dateFormatter = DateFormatter::create($locale, $values[$dateType], $values[$timeType], 'Europe/Brussels', DateFormatter::GREGORIAN, $pattern);
}
return $dateFormatter->format($date);
}
示例7: testIntlDate
public function testIntlDate()
{
$date = new \DateTime('2000-02-03 04:05', new \DateTimeZone('UTC'));
$formatter1 = \IntlDateFormatter::create('en@calendar=islamic-umalqura', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, "Europe/Berlin", \IntlDateFormatter::TRADITIONAL);
$formatter2 = \IntlDateFormatter::create('@calendar=islamic-civil', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, "Europe/Berlin", \IntlDateFormatter::TRADITIONAL);
// TODO investigate failure, probably because of different ICU version
//$this->assertEquals('AH 1420 Shawwal 27, Thu 05:05:00 GMT+01:00', $formatter1->format($date), 'islamic-umalqura' . self::INTLinfo());
//$this->assertEquals('AH 1420 Shawwal 127, Thu 05:05:00 GMT+01:00', $formatter2->format($date), 'islamic-civil' . self::INTLinfo('@calendar=islamic-civil'));
$formatter = \IntlDateFormatter::create('@calendar=japanese', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, "Europe/Berlin", \IntlDateFormatter::TRADITIONAL);
//$this->assertEquals('Heisei 12 M02 3, Thu 05:05:00 GMT+01:00', $formatter->format($date), 'islamic-civil' . self::INTLinfo('@calendar=japanese'));
}
示例8: twig_localized_date_filter
function twig_localized_date_filter($date, $dateFormat = 'medium', $timeFormat = 'medium', $locale = null)
{
$formatValues = array('none' => IntlDateFormatter::NONE, 'short' => IntlDateFormatter::SHORT, 'medium' => IntlDateFormatter::MEDIUM, 'long' => IntlDateFormatter::LONG, 'full' => IntlDateFormatter::FULL);
$formatter = IntlDateFormatter::create($locale !== null ? $locale : Locale::getDefault(), $formatValues[$dateFormat], $formatValues[$timeFormat]);
if (!$date instanceof DateTime) {
if (ctype_digit((string) $date)) {
$date = new DateTime('@' . $date);
$date->setTimezone(new DateTimeZone(date_default_timezone_get()));
} else {
$date = new DateTime($date);
}
}
return $formatter->format($date->getTimestamp());
}
示例9: filterLocalizedDatePattern
public function filterLocalizedDatePattern($date, $pattern, $locale = null)
{
if (!class_exists('IntlDateFormatter')) {
throw new \RuntimeException('The intl extension is needed to use intl-based filters.');
}
$formatter = \IntlDateFormatter::create($locale !== null ? $locale : \Locale::getDefault(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, date_default_timezone_get());
$formatter->setPattern($pattern);
if (!$date instanceof \DateTime) {
if (\ctype_digit((string) $date)) {
$date = new \DateTime('@' . $date);
$date->setTimezone(new \DateTimeZone(date_default_timezone_get()));
} else {
$date = new \DateTime($date);
}
}
return $formatter->format($date->getTimestamp());
}
示例10: onDataReady
/**
* Handles DateTime fields
*
* @param DataEvent $event
*/
public function onDataReady(DataEvent $event)
{
$data = array();
foreach ($event->getData() as $key => $row) {
foreach ($row as $field => $value) {
if ($value instanceof \DateTime) {
$formatter = \IntlDateFormatter::create($this->locale, static::$formats[$this->dateFormat], static::$formats[$this->timeFormat], $this->timezone, IntlDateFormatter::GREGORIAN, $this->format);
if (!$formatter) {
$formatter = IntlDateFormatter::create('en', static::$formats[$this->dateFormat], static::$formats[$this->timeFormat], $this->timezone, \IntlDateFormatter::GREGORIAN, $this->format);
}
$value = $formatter->format($value->getTimestamp());
}
$data[$key][$field] = $value;
}
}
$event->setData($data);
}
示例11: localeDateFilter
/**
* Translate a timestamp to a localized string representation.
* Parameters dateType and timeType defines a kind of format. Allowed values are (none|short|medium|long|full).
* Default is medium for the date and no time.
* @param mixed $date
* @param string $dateType
* @param string $timeType
* @return string The string representation
*/
public static function localeDateFilter($date, $dateType = 'medium', $timeType = 'none')
{
$values = array(
'none' => \IntlDateFormatter::NONE,
'short' => \IntlDateFormatter::SHORT,
'medium' => \IntlDateFormatter::MEDIUM,
'long' => \IntlDateFormatter::LONG,
'full' => \IntlDateFormatter::FULL,
);
$dateFormater = \IntlDateFormatter::create(\Locale::getDefault(), $values[$dateType], $values[$timeType]);
if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50304) {
$date = $date->getTimestamp();
}
return $dateFormater->format($date);
}
示例12: api_registros_por_ano
public function api_registros_por_ano()
{
$this->autoRender = false;
// dados do Angular
$dados = (array) json_decode(file_get_contents('php://input'), true);
// dados do usuário logado
$admin_logged = $this->getAdminLogged();
// busca aulas do usuário logado que a data seja pertencente ao ano selecionado
$lessons_table = TableRegistry::get("Lessons");
$user_id = empty($admin_logged['clinical_condition']) ? $admin_logged['user_id'] : $admin_logged['id'];
$where = ['user_id' => $user_id];
// executa a consulta
$lessons = $lessons_table->find()->where($where)->order(['Lessons.date' => 'DESC'])->contain(['LessonEntries' => function ($q) {
// join para buscar as entradas desta aula somente do usuário logado e para incluir os inputs tb
$admin_logged = $this->getAdminLogged();
$user_id = empty($admin_logged['clinical_condition']) ? $admin_logged['user_id'] : $admin_logged['id'];
$where2 = ['LessonEntries.user_id' => $user_id];
if (!empty($admin_logged['clinical_condition'])) {
$where2 = ['LessonEntries.user_id' => $admin_logged['id'], 'LessonEntries.model' => 'Users', 'LessonEntries.model_id' => $admin_logged['id']];
}
return $q->contain(['Inputs'])->where($where2);
}, 'LessonThemes' => function ($q) {
return $q->contain(['Themes']);
}, 'LessonHashtags' => function ($q) {
return $q->contain(['Hashtags']);
}])->all();
$meses = ["01" => 0, "02" => 0, "03" => 0, "04" => 0, "05" => 0, "06" => 0, "07" => 0, "08" => 0, "09" => 0, "10" => 0, "11" => 0, "12" => 0];
// inclui um campo com o mes do registro
foreach ($lessons as $l) {
$dateFormatter = \IntlDateFormatter::create(\Locale::getDefault(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, \date_default_timezone_get(), \IntlDateFormatter::GREGORIAN, 'EEEE');
$l->mes = $l->date->format("m");
$l->year = $l->date->format("Y");
$l->dia = ucfirst($dateFormatter->format($l->date));
$l->created = null;
$l->modified = null;
$l->date = $l->date->format("d/m");
$meses[$l->mes] = $meses[$l->mes] + 1;
}
$return = ['lessons' => $lessons, 'meses' => $meses];
echo json_encode($return);
}
示例13: handlePoolCreation
/**
* @param Request $request
* @param Pool $pool
*
* @return array|\Symfony\Component\HttpFoundation\RedirectResponse
*/
private function handlePoolCreation(Request $request, Pool $pool)
{
$form = $this->createForm(PoolType::class, $pool);
if ('POST' === $request->getMethod()) {
$form->handleRequest($request);
if ($form->isValid()) {
foreach ($pool->getEntries() as $entry) {
$entry->setPool($pool);
}
$dateFormatter = \IntlDateFormatter::create($request->getLocale(), \IntlDateFormatter::MEDIUM, \IntlDateFormatter::NONE);
$message = $this->get('translator')->trans('emails.created.message', ['%amount%' => $pool->getAmount(), '%eventdate%' => $dateFormatter->format($pool->getEventdate()->getTimestamp()), '%location%' => $pool->getLocation(), '%message%' => $pool->getMessage()]);
$pool->setCreationDate(new \DateTime());
$pool->setMessage($message);
$pool->setLocale($request->getLocale());
$this->get('doctrine.orm.entity_manager')->persist($pool);
$this->get('doctrine.orm.entity_manager')->flush();
return $this->redirect($this->generateUrl('pool_exclude', ['listUrl' => $pool->getListurl()]));
}
}
return ['form' => $form->createView()];
}
示例14: createAction
/**
* @Route("/", name="pool_create")
* @Template()
*/
public function createAction(Request $request)
{
$pool = new Pool();
$form = $this->createForm(new PoolType(), $pool);
if ('POST' === $request->getMethod()) {
$form->handleRequest($request);
if ($form->isValid()) {
foreach ($pool->getEntries() as $entry) {
$entry->setPool($pool);
}
$em = $this->getDoctrine()->getManager();
$dateFormatter = \IntlDateFormatter::create($request->getLocale(), \IntlDateFormatter::MEDIUM, \IntlDateFormatter::NONE);
$translator = $this->get('translator');
$message = $translator->trans('emails.created.message', array('%amount%' => $pool->getAmount(), '%date%' => $dateFormatter->format($pool->getDate()->getTimestamp()), '%message%' => $pool->getMessage()));
$pool->setMessage($message);
$pool->setLocale($request->getLocale());
$em->persist($pool);
$em->flush();
return $this->redirect($this->generateUrl('pool_exclude', array('listUrl' => $pool->getListurl())));
}
}
return array('form' => $form->createView());
}
示例15: parseTimestamp
/**
* Parse a string representation of a date to a timestamp.
*
* @param string $date
* @param string $locale
* @return int Timestamp
*
* @throws \Exception If fails parsing the string
*/
private function parseTimestamp($date, $locale = null)
{
// try time default formats
foreach ($this->formats as $timeFormat) {
// try date default formats
foreach ($this->formats as $dateFormat) {
$dateFormater = \IntlDateFormatter::create($locale ?: \Locale::getDefault(), $dateFormat, $timeFormat, date_default_timezone_get());
$timestamp = $dateFormater->parse($date);
if ($dateFormater->getErrorCode() == 0) {
return $timestamp;
}
}
}
// try other custom formats
$formats = array('MMMM yyyy');
foreach ($formats as $format) {
$dateFormater = \IntlDateFormatter::create($locale ?: \Locale::getDefault(), $this->formats['none'], $this->formats['none'], date_default_timezone_get(), \IntlDateFormatter::GREGORIAN, $format);
$timestamp = $dateFormater->parse($date);
if ($dateFormater->getErrorCode() == 0) {
return $timestamp;
}
}
throw new \Exception('"' . $date . '" could not be converted to \\DateTime');
}