This class contains information, such as date patterns, time patterns, and AM/PM designators. To create a DateTimeFormatInfo for a specific culture, create a CultureInfo for that culture and retrieve the CultureInfo.DateTimeFormat property. For example: $culture = new CultureInfo('en_AU'); $dtfi = $culture->DateTimeFormat; To create a DateTimeFormatInfo for the invariant culture, use DateTimeFormatInfo::getInstance($culture=null); you may pass a CultureInfo parameter $culture to get the DateTimeFormatInfo for a specific culture. DateTime values are formatted using standard or custom patterns stored in the properties of a DateTimeFormatInfo. The standard patterns can be replaced with custom patterns by setting the associated properties of DateTimeFormatInfo. The following table lists the standard format characters for each standard pattern and the associated DateTimeFormatInfo property that can be set to modify the standard pattern. The format characters are case-sensitive; for example, 'g' and 'G' represent slightly different patterns. Format Character Associated Property Example Format Pattern (en-US) -------------------------------------------------------------------------- d ShortDatePattern MM/dd/yyyy D LongDatePattern dddd, dd MMMM yyyy F FullDateTimePattern dddd, dd MMMM yyyy HH:mm:ss m, M MonthDayPattern MMMM dd r, R RFC1123Pattern ddd, dd MMM yyyy HH':'mm':'ss 'GMT' s SortableDateTimePattern yyyy'-'MM'-'dd'T'HH':'mm':'ss t ShortTimePattern HH:mm T LongTimePattern HH:mm:ss Y YearMonthPattern yyyy MMMM --------------------------------------------------------------------------
コード例 #1
0
ファイル: DateFormat.php プロジェクト: pradosoft/prado
 /**
  * Get the era. i.e. in gregorian, year > 0 is AD, else BC.
  * @todo How to support multiple Eras?, e.g. Japanese.
  * @param array getdate format.
  * @param string a pattern.
  * @return string era
  */
 protected function getEra($date, $pattern = 'G')
 {
     if ($pattern != 'G') {
         throw new Exception('The pattern for era is "G".');
     }
     $year = $date['year'];
     if ($year > 0) {
         return $this->formatInfo->getEra(1);
     } else {
         return $this->formatInfo->getEra(0);
     }
 }
コード例 #2
0
 function testGetInstance()
 {
     $format = DateTimeFormatInfo::getInstance('zh_CN');
     $pattern = 'yyyy-M-d';
     $this->assertEquals($pattern, $format->MediumDatePattern);
 }