当前位置: 首页>>代码示例>>PHP>>正文


PHP IntlDateFormatter类代码示例

本文整理汇总了PHP中IntlDateFormatter的典型用法代码示例。如果您正苦于以下问题:PHP IntlDateFormatter类的具体用法?PHP IntlDateFormatter怎么用?PHP IntlDateFormatter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IntlDateFormatter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: buildForm

 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $format = $options['format'];
     $pattern = null;
     $allowedFormatOptionValues = array(\IntlDateFormatter::FULL, \IntlDateFormatter::LONG, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT);
     // If $format is not in the allowed options, it's considered as the pattern of the formatter if it is a string
     if (!in_array($format, $allowedFormatOptionValues, true)) {
         if (is_string($format)) {
             $format = self::DEFAULT_FORMAT;
             $pattern = $options['format'];
         } else {
             throw new CreationException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom pattern');
         }
     }
     $formatter = new \IntlDateFormatter(\Locale::getDefault(), $format, \IntlDateFormatter::NONE, 'UTC', \IntlDateFormatter::GREGORIAN, $pattern);
     $formatter->setLenient(false);
     $builder->addViewTransformer(new DateTimeToLocalizedStringTransformer($options['data_timezone'], $options['user_timezone'], $format, \IntlDateFormatter::NONE, \IntlDateFormatter::GREGORIAN, $pattern));
     if ('string' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToStringTransformer($options['data_timezone'], $options['data_timezone'], 'Y-m-d')));
     } elseif ('timestamp' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer($options['data_timezone'], $options['data_timezone'])));
     } elseif ('array' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['data_timezone'], array('year', 'month', 'day'))));
     }
     $builder->setAttribute('date_pattern', $formatter->getPattern());
 }
开发者ID:senthilkumar3282,项目名称:LyraAdminBundle,代码行数:26,代码来源:DatePickerType.php

示例2: configureOptions

 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $format = function (Options $options) {
         $date_format = \IntlDateFormatter::NONE;
         $time_format = \IntlDateFormatter::NONE;
         if ($options['date_picker']) {
             $date_format = \IntlDateFormatter::SHORT;
         }
         if ($options['time_picker']) {
             $time_format = $options['with_seconds'] ? \IntlDateFormatter::MEDIUM : \IntlDateFormatter::SHORT;
         }
         $formater = new \IntlDateFormatter($options['locale'], $date_format, $time_format, $options['user_timezone'], \IntlDateFormatter::GREGORIAN, null);
         $formater->setLenient(false);
         $pattern = $formater->getPattern();
         if (false === strpos($pattern, 'yyyy')) {
             if (false !== strpos($pattern, 'yy')) {
                 $pattern = str_replace('yy', 'yyyy', $pattern);
             } elseif (false !== strpos($pattern, 'y')) {
                 $pattern = str_replace('y', 'yyyy', $pattern);
             }
         }
         return $pattern;
     };
     $resolver->setDefaults(array('widget' => 'single_text', 'locale' => \Locale::getDefault(), 'user_timezone' => null, 'date_picker' => true, 'time_picker' => true, 'time_picker_first' => false, 'button_id' => null, 'open_focus' => true, 'hour_min' => null, 'hour_max' => null, 'hour_step' => null, 'minute_min' => null, 'minute_max' => null, 'minute_step' => null, 'second_min' => null, 'second_max' => null, 'second_step' => null, 'format' => $format, 'empty_value' => null, 'with_minutes' => true, 'with_seconds' => false));
 }
开发者ID:mcdir,项目名称:SonatraFormExtensionsBundle,代码行数:28,代码来源:DateTimeJqueryTypeExtension.php

示例3: d

function d(IntlDateFormatter $df)
{
    global $ts;
    echo $df->format($ts), "\n";
    var_dump($df->getCalendar(), $df->getCalendarObject()->getType(), $df->getCalendarObject()->getTimeZone()->getId());
    echo "\n";
}
开发者ID:badlamer,项目名称:hhvm,代码行数:7,代码来源:dateformat_get_set_calendar_variant2.php

示例4: createView

 public function createView(ViewFactory $factory, $data, array $options) : ViewInterface
 {
     $dateFormat = $this->resolveFormat($options['date_format']);
     $timeFormat = $this->resolveFormat($options['time_format']);
     $formatter = new \IntlDateFormatter(\Locale::getDefault(), $dateFormat, $timeFormat, null, \IntlDateFormatter::GREGORIAN);
     return new DateTimeView($formatter->format($data), $data, $options['tag']);
 }
开发者ID:symfony-cmf,项目名称:content-type,代码行数:7,代码来源:DateTimeType.php

示例5: formatValue

 /**
  * Returns a string representation of the value.
  *
  * This method returns the equivalent PHP tokens for most scalar types
  * (i.e. "false" for false, "1" for 1 etc.). Strings are always wrapped
  * in double quotes ("). Objects, arrays and resources are formatted as
  * "object", "array" and "resource". If the parameter $prettyDateTime
  * is set to true, {@link \DateTime} objects will be formatted as
  * RFC-3339 dates ("Y-m-d H:i:s").
  *
  * Be careful when passing message parameters to a constraint violation
  * that (may) contain objects, arrays or resources. These parameters
  * should only be displayed for technical users. Non-technical users
  * won't know what an "object", "array" or "resource" is and will be
  * confused by the violation message.
  *
  * @param mixed $value          The value to format as string
  * @param bool  $prettyDateTime Whether to format {@link \DateTime}
  *                              objects as RFC-3339 dates ("Y-m-d H:i:s")
  *
  * @return string The string representation of the passed value
  */
 protected function formatValue($value, $prettyDateTime = false)
 {
     if ($prettyDateTime && $value instanceof \DateTime) {
         if (class_exists('IntlDateFormatter')) {
             $locale = \Locale::getDefault();
             $formatter = new \IntlDateFormatter($locale, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT);
             return $formatter->format($value);
         }
         return $value->format('Y-m-d H:i:s');
     }
     if (is_object($value)) {
         return 'object';
     }
     if (is_array($value)) {
         return 'array';
     }
     if (is_string($value)) {
         return '"' . $value . '"';
     }
     if (is_resource($value)) {
         return 'resource';
     }
     if (null === $value) {
         return 'null';
     }
     if (false === $value) {
         return 'false';
     }
     if (true === $value) {
         return 'true';
     }
     return (string) $value;
 }
开发者ID:raphael-thibierge,项目名称:ProgWebServerProject,代码行数:55,代码来源:ConstraintValidator.php

示例6: query

 public function query($departure, $arrival, \DateTime $date = null)
 {
     $date = $date ? $date : new \DateTime();
     $fmt = new \IntlDateFormatter('en_EN', \IntlDateFormatter::FULL, \IntlDateFormatter::NONE, date_default_timezone_get(), \IntlDateFormatter::TRADITIONAL);
     $response = $this->client->post('bin/query.exe/fn', array('headers' => array('host' => 'fahrplan.sbb.ch', 'origin' => 'http://fahrplan.sbb.ch', 'referer' => 'http://fahrplan.sbb.ch/bin/query.exe/fn'), 'form_params' => array('queryPageDisplayed' => 'yes', 'HWAI=JS!ajax' => 'yes', 'HWAI=JS!js' => 'yes', 'HWAI' => '~CONNECTION!', 'REQ0Total_KissRideMotorClass' => '404', 'REQ0Total_KissRideCarClass' => '5', 'REQ0Total_KissRide_maxDist' => '10000000', 'REQ0Total_KissRide_minDist' => '0', 'REQComparisonCarload' => '0', 'REQ0JourneyStopsS0G' => $departure['value'], 'REQ0JourneyStopsS0ID' => $departure['id'], 'REQ0JourneyStopsS0A' => '255', 'REQ0JourneyStopsZ0G' => $arrival['value'], 'REQ0JourneyStopsZ0ID' => $arrival['id'], 'REQ0JourneyStopsZ0A' => '255', 'REQ0JourneyStops1.0G' => '', 'REQ0JourneyStops1.0A' => '1', 'REQ0JourneyStopover1' => '', 'date' => sprintf('%s, %s', substr($fmt->format($date), 0, 2), $date->format('d-m-y')), 'REQ0JourneyTime' => $date->format('H:i'), 'REQ0HafasSearchForw' => '1', 'REQ0JourneyStops2.0G' => '', 'REQ0JourneyStops2.0A' => '1', 'REQ0JourneyStopover2' => '', 'REQ0JourneyStops3.0G' => '', 'REQ0JourneyStops3.0A' => '1', 'REQ0JourneyStopover3' => '', 'REQ0JourneyStops4.0G' => '', 'REQ0JourneyStops4.0A' => '1', 'REQ0JourneyStopover4' => '', 'REQ0JourneyStops5.0G' => '', 'REQ0JourneyStops5.0A' => '1', 'REQ0JourneyStopover5' => '', 'existOptimizePrice' => '0', 'existUnsharpSearch' => 'yes', 'REQ0HafasChangeTime' => '0:1', 'existHafasAttrExc' => 'yes', 'REQ0JourneyProduct_prod_0' => '1', 'existProductBits0' => 'yes', 'REQ0JourneyProduct_prod_1' => '1', 'REQ0JourneyProduct_prod_2' => '1', 'REQ0JourneyProduct_prod_3' => '1', 'REQ0JourneyProduct_prod_4' => '1', 'REQ0JourneyProduct_prod_5' => '1', 'REQ0JourneyProduct_prod_6' => '1', 'REQ0JourneyProduct_prod_7' => '1', 'REQ0JourneyProduct_prod_8' => '1', 'REQ0JourneyProduct_prod_9' => '1', 'REQ0JourneyProduct_opt_section_0_list' => '0:0000', 'disableBaim' => 'yes', 'REQ0HafasHandicapLimit' => '4:4', 'changeQueryInputData' => 'yes', 'start' => 'Chercher correspondance')));
     $crawler = new Crawler(utf8_encode((string) $response->getBody()));
     $overviews = array();
     $date = '';
     // Get overviews
     $crawler->filter('.hfs_overview .overview')->each(function (Crawler $node) use(&$overviews, &$date) {
         // Update date
         if (false !== strpos($node->getNode(0)->getAttribute('class'), 'dateHint')) {
             // Subtract 8 last chars
             $date = substr($text = trim($node->text()), ($len = strlen($text)) - 8, $len);
             return;
         }
         $overviews[] = array_filter(array($date, count($n = $node->filter('.time.departure')) ? substr(trim($n->text()), 0, 5) : null, count($n = $node->filter('.time.arrival')) ? substr(trim($n->text()), 0, 5) : null, count($n = $node->filter('.duration')) ? trim($n->text()) : null, count($n = $node->filter('.changes')) ? trim($n->text()) : null, count($n = $node->filter('.products')) ? trim($n->text()) : null, sprintf('%s%s', count($n = $node->filter('.top img')) ? trim($n->attr('alt')) : null, count($n = $node->filter('.him_icon img')) ? trim($n->attr('alt')) : null)), function ($v) {
             return $v !== null;
         });
     });
     // Combine overviews
     $_overviews = array();
     for ($i = 0; $i < count($overviews) / 2; $i++) {
         $overview = $overviews[$i * 2] + $overviews[$i * 2 + 1];
         ksort($overview);
         $_overviews[] = array_combine(array('date', 'departure', 'arrival', 'duration', 'change', 'product', 'infos'), $overview);
     }
     return $_overviews;
 }
开发者ID:maidmaid,项目名称:cffie,代码行数:29,代码来源:CffClient.php

示例7: format

 public function format($datetime, $dateFormat = null, $timeFormat = null, $timezone = null, $locale = null)
 {
     $dt = null;
     $tz = null;
     if (null !== $timezone) {
         $tz = is_string($timezone) ? new \DateTimeZone($timezone) : $timezone;
     }
     if ($datetime instanceof \DateTimeImmutable) {
         $dt = new \DateTime($datetime->format('Y-m-d H:i:s'), $tz);
     } elseif (!$datetime instanceof \DateTime) {
         $dt = new \DateTime($datetime, $tz);
     } else {
         $dt = clone $datetime;
     }
     if (null === $tz) {
         $tz = $dt->getTimezone();
     }
     if (null === $locale) {
         $locale = \Locale::getDefault();
     }
     if (null === $dateFormat) {
         $dateFormat = \IntlDateFormatter::MEDIUM;
     }
     if (null === $timeFormat) {
         $timeFormat = \IntlDateFormatter::NONE;
     }
     $currentLocale = \Locale::getDefault();
     \Locale::setDefault($locale);
     $formatter = new \IntlDateFormatter($locale, $dateFormat, $timeFormat, $tz);
     $result = $formatter->format($dt);
     \Locale::setDefault($currentLocale);
     return $result;
 }
开发者ID:Symfomany,项目名称:laravelcinema,代码行数:33,代码来源:DateHelper.php

示例8: d

function d(IntlDateFormatter $df)
{
    global $ts;
    echo $df->format($ts), "\n";
    var_dump($df->getTimeZoneID(), $df->getTimeZone()->getID());
    echo "\n";
}
开发者ID:badlamer,项目名称:hhvm,代码行数:7,代码来源:dateformat_get_set_timezone_variant2.php

示例9: finishView

 /**
  * {@inheritdoc}
  */
 public function finishView(FormView $view, FormInterface $form, array $options)
 {
     $format = $options['format'];
     if (isset($options['date_format']) && is_string($options['date_format'])) {
         $format = $options['date_format'];
     } elseif (is_int($format)) {
         $timeFormat = $options['dp_pick_time'] ? DateTimeType::DEFAULT_TIME_FORMAT : \IntlDateFormatter::NONE;
         $intlDateFormatter = new \IntlDateFormatter(\Locale::getDefault(), $format, $timeFormat, null, \IntlDateFormatter::GREGORIAN, null);
         $format = $intlDateFormatter->getPattern();
     }
     // use seconds if it's allowe in format
     $options['dp_use_seconds'] = strpos($format, 's') !== false;
     $view->vars['moment_format'] = $this->formatConverter->convert($format);
     $view->vars['type'] = 'text';
     $dpOptions = array();
     foreach ($options as $key => $value) {
         if (false !== strpos($key, "dp_")) {
             // We remove 'dp_' and camelize the options names
             $dpKey = substr($key, 3);
             $dpKey = preg_replace_callback('/_([a-z])/', function ($c) {
                 return strtoupper($c[1]);
             }, $dpKey);
             $dpOptions[$dpKey] = $value;
         }
     }
     $view->vars['datepicker_use_button'] = empty($options['datepicker_use_button']) ? false : true;
     $view->vars['dp_options'] = $dpOptions;
 }
开发者ID:saberyounis,项目名称:Sonata-Project,代码行数:31,代码来源:BasePickerType.php

示例10: buildView

 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $value = $form->getViewData();
     // set string representation
     if (true === $value) {
         $value = 'true';
     } elseif (false === $value) {
         $value = 'false';
     } elseif (null === $value) {
         $value = 'null';
     } elseif (is_array($value)) {
         $value = implode(', ', $value);
     } elseif ($value instanceof \DateTime) {
         $dateFormat = is_int($options['date_format']) ? $options['date_format'] : DateType::DEFAULT_FORMAT;
         $timeFormat = is_int($options['time_format']) ? $options['time_format'] : DateType::DEFAULT_FORMAT;
         $calendar = \IntlDateFormatter::GREGORIAN;
         $pattern = is_string($options['date_pattern']) ? $options['date_pattern'] : null;
         $formatter = new \IntlDateFormatter(\Locale::getDefault(), $dateFormat, $timeFormat, 'UTC', $calendar, $pattern);
         $formatter->setLenient(false);
         $value = $formatter->format($value);
     } elseif (is_object($value)) {
         if (method_exists($value, '__toString')) {
             $value = $value->__toString();
         } else {
             $value = get_class($value);
         }
     }
     $view->vars['value'] = (string) $value;
 }
开发者ID:GeneralMediaCH,项目名称:GenemuFormBundle,代码行数:32,代码来源:PlainType.php

示例11: openfit_base_preprocess_comment

function openfit_base_preprocess_comment(&$variables)
{
    $openfit_node_types = array('activity' => TRUE);
    if (!isset($variables['node']) || !isset($openfit_node_types[$variables['node']->type])) {
        return;
    }
    $comment = $variables['comment'];
    // Remove the standard comment links: reply, edit, delete
    unset($variables['content']['links']['comment']['#links']);
    // Add a delete menu if the user posted the comment or is admin
    global $user;
    if (user_access('administer comments') || $user->uid == $comment->uid) {
        $url = drupal_get_path_alias('node/' . $variables['node']->nid) . '/comments';
        $variables['content']['links']['comment']['#links'] = array('comment-delete' => array('title' => '&nbsp;', 'href' => 'comment/' . $comment->cid . '/delete', 'query' => array('destination' => $url), 'html' => TRUE));
    }
    // Display "XX ago" for posts less than 1 day, otherwise use locale to format datetime
    $ago = time() - $comment->created;
    if ($ago < 86400) {
        $variables['created'] = t('!interval ago', array('!interval' => format_interval(time() - $comment->created)));
    } else {
        $locale = OpenFitUserSetting::getCurrentUserLocale();
        $fmt = new IntlDateFormatter($locale, IntlDateFormatter::SHORT, IntlDateFormatter::SHORT);
        $created = new DateTime('now');
        $created->setTimestamp($comment->created);
        $variables['created'] = $fmt->format($created);
    }
    $variables['submitted'] = $variables['author'] . '&nbsp;' . '<time datetime="' . $variables['datetime'] . '" pubdate="pubdate">' . $variables['created'] . '</time>';
}
开发者ID:NeilBryant,项目名称:sufferhub,代码行数:28,代码来源:template.php

示例12: __invoke

 public function __invoke($value, $format = 'Y-m-d H:i:s', $dateType = \IntlDateFormatter::SHORT, $timeType = \IntlDateFormatter::NONE)
 {
     $translator = $this->getServiceLocator()->getServiceLocator()->get('translator');
     $locale = $translator->getTranslator()->getLocale();
     $formatter = new \IntlDateFormatter($locale, $dateType, $timeType, null, null, $format);
     $date = new \DateTime($value);
     return $formatter->format($date);
 }
开发者ID:omusico,项目名称:Base,代码行数:8,代码来源:Datetime.php

示例13: getFormat

 /**
  * {@inheritdoc}
  */
 public function getFormat($locale)
 {
     if (isset($this->dateFormats[$locale])) {
         return $this->dateFormats[$locale];
     }
     $formatter = new \IntlDateFormatter($locale, \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE);
     $icuFormat = $formatter->getPattern();
     return $this->converter->convert($icuFormat);
 }
开发者ID:alexisfroger,项目名称:pim-community-dev,代码行数:12,代码来源:DateFormatProvider.php

示例14: format

 /**
  * {@inheritdoc}
  */
 public function format($value, array $options = [])
 {
     if (!$value instanceof \DateTimeInterface) {
         throw new InvalidTypeException(sprintf('The number formatter expects a numeric value, got "%s".', is_object($value) ? get_class($value) : gettype($value)));
     }
     $formatter = new \IntlDateFormatter($this->localeContext->getLocale(), isset($options['date_format']) ? $options['date_format'] : \IntlDateFormatter::MEDIUM, isset($options['time_format']) ? $options['time_format'] : \IntlDateFormatter::MEDIUM, isset($options['timezone']) ? $options['timezone'] : $value->getTimezone(), isset($options['calendar']) ? $options['calendar'] : null, isset($options['pattern']) ? $options['pattern'] : null);
     $formatter->setLenient(isset($options['lenient']) ? $options['lenient'] : false);
     return $formatter->format($value);
 }
开发者ID:php-lug,项目名称:lug,代码行数:12,代码来源:DateTimeFormatter.php

示例15: formatDate

 private function formatDate(\DateTime $date)
 {
     if (null === $this->options['format']) {
         $locale = \Locale::getDefault();
         $ftm = new \IntlDateFormatter($locale, \IntlDateFormatter::SHORT, \IntlDateFormatter::SHORT);
         return $ftm->format($date);
     }
     return $date->format($this->options['format']);
 }
开发者ID:Newman101,项目名称:WellCommerce,代码行数:9,代码来源:DateTransformer.php


注:本文中的IntlDateFormatter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。