當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。