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


PHP DrupalDateTime::createFromFormat方法代码示例

本文整理汇总了PHP中Drupal\Core\Datetime\DrupalDateTime::createFromFormat方法的典型用法代码示例。如果您正苦于以下问题:PHP DrupalDateTime::createFromFormat方法的具体用法?PHP DrupalDateTime::createFromFormat怎么用?PHP DrupalDateTime::createFromFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Datetime\DrupalDateTime的用法示例。


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

示例1: valueCallback

 /**
  * {@inheritdoc}
  */
 public static function valueCallback(&$element, $input, FormStateInterface $form_state)
 {
     if ($input !== FALSE) {
         $date_input = $element['#date_date_element'] != 'none' && !empty($input['date']) ? $input['date'] : '';
         $time_input = $element['#date_time_element'] != 'none' && !empty($input['time']) ? $input['time'] : '';
         $date_format = $element['#date_date_element'] != 'none' ? static::getHtml5DateFormat($element) : '';
         $time_format = $element['#date_time_element'] != 'none' ? static::getHtml5TimeFormat($element) : '';
         $timezone = !empty($element['#date_timezone']) ? $element['#date_timezone'] : NULL;
         // Seconds will be omitted in a post in case there's no entry.
         if (!empty($time_input) && strlen($time_input) == 5) {
             $time_input .= ':00';
         }
         try {
             $date_time_format = trim($date_format . ' ' . $time_format);
             $date_time_input = trim($date_input . ' ' . $time_input);
             $date = DrupalDateTime::createFromFormat($date_time_format, $date_time_input, $timezone);
         } catch (\Exception $e) {
             $date = NULL;
         }
         $input = array('date' => $date_input, 'time' => $time_input, 'object' => $date);
     } else {
         $date = $element['#default_value'];
         if ($date instanceof DrupalDateTime && !$date->hasErrors()) {
             $input = array('date' => $date->format($element['#date_date_format']), 'time' => $date->format($element['#date_time_format']), 'object' => $date);
         } else {
             $input = array('date' => '', 'time' => '', 'object' => NULL);
         }
     }
     return $input;
 }
开发者ID:papillon-cendre,项目名称:d8,代码行数:33,代码来源:Datetime.php

示例2: getValue

 /**
  * {@inheritdoc}
  */
 public function getValue($langcode = NULL)
 {
     if ($this->date !== NULL) {
         return $this->date;
     }
     $item = $this->getParent();
     $value = $item->{$this->definition->getSetting('date source')};
     $storage_format = $item->getFieldDefinition()->getSetting('datetime_type') == 'date' ? DATETIME_DATE_STORAGE_FORMAT : DATETIME_DATETIME_STORAGE_FORMAT;
     try {
         $date = DrupalDateTime::createFromFormat($storage_format, $value, DATETIME_STORAGE_TIMEZONE);
         if ($date instanceof DrupalDateTime && !$date->hasErrors()) {
             $this->date = $date;
         }
     } catch (\Exception $e) {
         // @todo Handle this.
     }
     return $this->date;
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:21,代码来源:DateTimeComputed.php

示例3: providerTestInvalidDateDiff

 /**
  * Provides data for date tests.
  *
  * @return array
  *   An array of arrays, each containing the input parameters for
  *   DateTimePlusTest::testInvalidDateDiff().
  *
  * @see DateTimePlusTest::testInvalidDateDiff()
  */
 public function providerTestInvalidDateDiff()
 {
     $settings = ['langcode' => 'en'];
     $utc_tz = new \DateTimeZone('UTC');
     return array(array('input1' => DrupalDateTime::createFromFormat('U', 3600, $utc_tz, $settings), 'input2' => '1970-01-01 00:00:00', 'absolute' => FALSE), array('input1' => DrupalDateTime::createFromFormat('U', 3600, $utc_tz, $settings), 'input2' => NULL, 'absolute' => FALSE));
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:15,代码来源:DrupalDateTimeTest.php


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