(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL intl >= 1.0.0)
IntlDateFormatter::getPattern -- datefmt_get_pattern — 取得 IntlDateFormatter 使用的模式
物件導向風格
程序式風格
取得格式器使用的模式。
formatter
格式器資源。
用於格式化/剖析的模式字串,或是在失敗時回傳 false
。
範例 #1 datefmt_get_pattern() 範例
<?php
$fmt = datefmt_create(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN,
'MM/dd/yyyy'
);
echo '格式器的模式為:' . datefmt_get_pattern($fmt);
echo '第一個使用此模式格式化的輸出為 ' . datefmt_format($fmt, 0);
datefmt_set_pattern($fmt,'yyyymmdd hh:mm:ss z');
echo '現在格式器的模式為:' . datefmt_get_pattern($fmt);
echo '第二個使用此模式格式化的輸出為 ' . datefmt_format($fmt, 0);
?>
範例 #2 物件導向範例
<?php
$fmt = new IntlDateFormatter(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN,
'MM/dd/yyyy'
);
echo '格式化器的模式為:' . $fmt->getPattern();
echo '第一個格式化輸出為 ' . $fmt->format(0);
$fmt->setPattern('yyyymmdd hh:mm:ss z');
echo '現在格式化器的模式為:' . $fmt->getPattern();
echo '第二個格式化輸出為 ' . $fmt->format(0);
?>
以上範例將輸出
pattern of the formatter is : MM/dd/yyyy First Formatted output is 12/31/1969 Now pattern of the formatter is : yyyymmdd hh:mm:ss z Second Formatted output is 19690031 04:00:00 PST