IntLDateFormatterを使用して、非グレゴリオ日の日付を変換する
質問
Gregorian以外の日付をIntlDateFormatter
を使用して他のカレンダータイプに変換する方法。
"1392-01-02"
からpersian
CalenderにConvert islamic
を使用します。私は次のコードを試しましたが、カレンダーを変換しません:
$formatter = IntlDateFormatter::create('en_US@calendar=persian', IntlDateFormatter::FULL,
IntlDateFormatter::FULL, 'Asia/Tokyo',IntlDateFormatter::TRADITIONAL,'yy-MM-dd');
$formatter->setCalendar(IntlDateFormatter::GREGORIAN);
echo $formatter->format($formatter->parse("1392-2-31"));
. 解決
IntlCalendar
のインスタンスとして変換して、その日付をそのset($year,$month,$day)
メソッドを使用して設定します。
$time = IntlCalendar::createInstance("Asia/Tokyo", "en_US@calendar=persian");
$time->set(1392,2,31);
//alternative way to define time using parse
/**
These constants are used to specify different formats in the constructor for DateType
and TimeType.
IntlDateFormatter::NONE (integer)
Do not include this element
IntlDateFormatter::FULL (integer)
Completely specified style (Tuesday, April 12, 1952 AD or 3:30:42pm PST)
IntlDateFormatter::LONG (integer)
Long style (January 12, 1952 or 3:30:32pm)
IntlDateFormatter::MEDIUM (integer)
Medium style (Jan 12, 1952)
IntlDateFormatter::SHORT (integer)
Most abbreviated style, only essential data (12/13/52 or 3:30pm)
*/
$fmt = new IntlDateFormatter(
'en_US@calendar=persian',
IntlDateFormatter::SHORT, //date format
IntlDateFormatter::NONE, //time format
'Asia/Tokyo',
IntlDateFormatter::TRADITIONAL
);
$time = $fmt->parse('3/31/1392 AP');
$formatter = IntlDateFormatter::create("en_US@calendar=islamic",
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'Asia/Tokyo',
IntlDateFormatter::TRADITIONAL);
print $formatter->format($time);
//Friday, Shaʻban 13, 1434 AH at 8:52:23 AM Japan Standard Time
. 所属していません StackOverflow