note 105460 modified in intldateformatter.create by danbrown

From: Date: Sat, 20 Aug 2011 15:59:21 +0000
Subject: note 105460 modified in intldateformatter.create by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-182603@lists.php.net to get a copy of this message
It should be noted that the locale string passed into IntlDateFormatter's constructor supports UCA keywords. So you can, for example, do things like this to output the year as a Japanese era year: <?php $now = new DateTime(); //DateTime is a core PHP class as of version 5.2.0 $formatter = new IntlDateFormatter('ja_JP', IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'Asia/Tokyo', IntlDateFormatter::GREGORIAN); echo 'It is now: "' . $formatter->format($now) . '" in Tokyo' . "\n"; //above gives [It is now: "2011年8月19日金曜日 23時32分27秒JST" in Tokyo] $formatter = new IntlDateFormatter('ja_JP@calendar=japanese', IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'Asia/Tokyo', IntlDateFormatter::TRADITIONAL); echo 'It is now: "' . $formatter->format($now) . '" in Tokyo' . "\n"; //above gives [It is now: "平成23年8月19日金曜日 23時32分27秒JST" in Tokyo] ?> --was-- It should be noted that the locale string passed into IntlDateFormatter's constructor supports UCA keywords. So you can, for example, do things like this to output the year as a Japanese era year: $now = new DateTime(); //DateTime is a core PHP class as of version 5.2.0 $formatter = new IntlDateFormatter('ja_JP', IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'Asia/Tokyo', IntlDateFormatter::GREGORIAN); echo 'It is now: "' . $formatter->format($now) . '" in Tokyo' . "\n"; //above gives [It is now: "2011年8月19日金曜日 23時32分27秒JST" in Tokyo] $formatter = new IntlDateFormatter('ja_JP@calendar=japanese', IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'Asia/Tokyo', IntlDateFormatter::TRADITIONAL); echo 'It is now: "' . $formatter->format($now) . '" in Tokyo' . "\n"; //above gives [It is now: "平成23年8月19日金曜日 23時32分27秒JST" in Tokyo] http://php.net/manual/en/intldateformatter.create.php

« previous php.notes (#182603) next »