當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DateFormatter::getSampleDateFormats方法代碼示例

本文整理匯總了PHP中Drupal\Core\Datetime\DateFormatter::getSampleDateFormats方法的典型用法代碼示例。如果您正苦於以下問題:PHP DateFormatter::getSampleDateFormats方法的具體用法?PHP DateFormatter::getSampleDateFormats怎麽用?PHP DateFormatter::getSampleDateFormats使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Drupal\Core\Datetime\DateFormatter的用法示例。


在下文中一共展示了DateFormatter::getSampleDateFormats方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: form

 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form['label'] = array('#type' => 'textfield', '#title' => 'Name', '#maxlength' => 100, '#description' => t('Name of the date format'), '#default_value' => $this->entity->label());
     $form['id'] = array('#type' => 'machine_name', '#description' => t('A unique machine-readable name. Can only contain lowercase letters, numbers, and underscores.'), '#disabled' => !$this->entity->isNew(), '#default_value' => $this->entity->id(), '#machine_name' => array('exists' => array($this, 'exists'), 'replace_pattern' => '([^a-z0-9_]+)|(^custom$)', 'error' => $this->t('The machine-readable name must be unique, and can only contain lowercase letters, numbers, and underscores. Additionally, it can not be the reserved word "custom".')));
     $form['date_format_pattern'] = array('#type' => 'textfield', '#title' => t('Format string'), '#maxlength' => 100, '#description' => $this->t('A user-defined date format. See the <a href="@url">PHP manual</a> for available options.', array('@url' => 'http://php.net/manual/function.date.php')), '#required' => TRUE, '#attributes' => ['data-drupal-date-formatter' => 'source'], '#field_suffix' => ' <small class="js-hide" data-drupal-date-formatter="preview">' . $this->t('Displayed as %date_format', ['%date_format' => '']) . '</small>');
     $form['langcode'] = array('#type' => 'language_select', '#title' => t('Language'), '#languages' => LanguageInterface::STATE_ALL, '#default_value' => $this->entity->language()->getId());
     $form['#attached']['drupalSettings']['dateFormats'] = $this->dateFormatter->getSampleDateFormats();
     $form['#attached']['library'][] = 'system/drupal.system.date';
     return parent::form($form, $form_state);
 }
開發者ID:jeyram,項目名稱:camp-gdl,代碼行數:13,代碼來源:DateFormatFormBase.php

示例2: testGetSampleDateFormats

 /**
  * Tests the getSampleDateFormats method.
  *
  * @covers \Drupal\Core\Datetime\DateFormatter::getSampleDateFormats
  */
 public function testGetSampleDateFormats()
 {
     $timestamp = strtotime('2015-03-22 14:23:00');
     $expected = $this->dateFormatter->getSampleDateFormats('en', $timestamp, 'Australia/Sydney');
     // Removed characters related to timezone 'e' and 'T', as test does not have
     // timezone set.
     $date_characters = 'dDjlNSwzWFmMntLoYyaABgGhHisuIOPZcrU';
     $date_chars = str_split($date_characters);
     foreach ($date_chars as $val) {
         $this->assertEquals($expected[$val], date($val, $timestamp));
     }
 }
開發者ID:318io,項目名稱:318-io,代碼行數:17,代碼來源:DateTest.php


注:本文中的Drupal\Core\Datetime\DateFormatter::getSampleDateFormats方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。