CakeFest 2024: The Official CakePHP Conference

IntlDateFormatter::create

datefmt_create

IntlDateFormatter::__construct

(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL intl >= 1.0.0)

IntlDateFormatter::create -- datefmt_create -- IntlDateFormatter::__constructBir tarih biçemleyici oluşturur

Açıklama

Nesne yönelimli kullanım

public static IntlDateFormatter::create(
    ?string $yerel,
    int $tarih_türü = IntlDateFormatter::FULL,
    int $saat_türü = IntlDateFormatter::FULL,
    IntlTimeZone|DateTimeZone|string|null $zaman_dilimi = null,
    IntlCalendar|int|null $takvim = null,
    ?string $kalıp = null
): ?IntlDateFormatter

Nesne yönelimli kullanım (kurucu)

public IntlDateFormatter::__construct(
    ?string $yerel,
    int $tarih_türü = IntlDateFormatter::FULL,
    int $saat_türü = IntlDateFormatter::FULL,
    IntlTimeZone|DateTimeZone|string|null $zaman_dilimi = null,
    IntlCalendar|int|null $takvim = null,
    ?string $kalıp = null
)

Yordamsal kullanım

datefmt_create(
    ?string $yerel,
    int $tarih_türü = IntlDateFormatter::FULL,
    int $saat_türü = IntlDateFormatter::FULL,
    IntlTimeZone|DateTimeZone|string|null $zaman_dilimi = null,
    IntlCalendar|int|null $takvim = null,
    ?string $kalıp = null
): ?IntlDateFormatter

Bir tarih biçemleyici oluşturur

Bağımsız Değişkenler

yerel

Biçemleme ve çözümleme için kullanılacak yerel veya intl.default_locale ini yönergesinde belirtilen değeri kullanmak için null.

tarih_türü

Kullanılacak tarih türü IntlDateFormatter sabitlerinden biri olmalıdır. IntlDateFormatter::FULL ön tanımlıdır.

saat_türü

Kullanılacak saat türü IntlDateFormatter sabitlerinden biri olmalıdır. IntlDateFormatter::FULL ön tanımlıdır.

zaman_dilimi

Zaman dilimi. Öntanımlı değer (null belirtilirse kullanılan), date_default_timezone_get() tarafından döndürülen veya varsa, takvim bağımsız değişkeni için aktarılan IntlCalendar nesnesinde tanımlı olandır. Bu değer, ICU'nun veritabanında geçerli bir tanımlayıcı veya GMT-05:30 gibi açık bir konumu temsil eden bir değer olmalıdır.

takvim

Biçemleme ve çözümleme için kullanılacak takvim. Öntanımlı değer, IntlDateFormatter::GREGORIAN sabitine karşılık gelen null değeridir. Bu, IntlDateFormatter takvim sabitlerinden biri veya IntlCalendar nesnesi olabilir. Aktarılan herhangi bir IntlCalendar nesnesi kopyalanır; IntlDateFormatter tarafından değiştirilmez. Bu, kullanılan takvim türünü (Gregoryen, İslami, Fars vb.) ve zaman_dilimi bağımsız değişkeni için null değeri verilirse kullanılan saat dilimini de belirler.

kalıp

Biçemleme ve çözümleme için kullanılacak isteğe beğlı kalıp. Olası kalıplar için bkz: » https://unicode-org.github.io/icu/userguide/format_parse/datetime/

Dönen Değerler

Oluşturulan IntlDateFormatter nesnesi veya başarısızlık durumunda null döner.

Sürüm Bilgisi

Sürüm: Açıklama
8.1.0

tarih_türü ve saat_türü belirtmek artık isteğe bağlı.

Örnekler

Örnek 1 - datefmt_create() örneği

<?php
$fmt
= datefmt_create("tr_TR", IntlDateFormatter::FULL,
IntlDateFormatter::FULL,'Europe/Istanbul',
IntlDateFormatter::GREGORIAN);
echo
"İlk biçemli çıktı: ".datefmt_format($fmt, 1234567890);
$fmt = datefmt_create("en-US", IntlDateFormatter::FULL,
IntlDateFormatter::FULL, 'Europe/Istanbul',
IntlDateFormatter::GREGORIAN);
echo
"\nİkinci biçemli çıktı: ".datefmt_format($fmt, 1234567890);

$fmt = datefmt_create("tr_TR", IntlDateFormatter::FULL,
IntlDateFormatter::FULL, 'Europe/Istanbul',
IntlDateFormatter::GREGORIAN, "dd/MM/yyyy");
echo
"\nİlk kalıbın çıktısı: ".datefmt_format( $fmt, 1234567890);
$fmt = datefmt_create("en-US", IntlDateFormatter::FULL,
IntlDateFormatter::FULL, 'Europe/Istanbul',
IntlDateFormatter::GREGORIAN, "MM/dd/yyyy");
echo
"\nİkinci kalıbın çıktısı: ".datefmt_format($fmt, 1234567890);
?>

Örnek 2 - Nesne yönelimli kullanım örneği

<?php
$fmt
= new IntlDateFormatter("tr_TR", IntlDateFormatter::FULL,
IntlDateFormatter::FULL,'Europe/Istanbul',
IntlDateFormatter::GREGORIAN);
echo
"İlk biçemli çıktı: ".$fmt->format(1234567890);
$fmt = new IntlDateFormatter("en-US", IntlDateFormatter::FULL,
IntlDateFormatter::FULL, 'Europe/Istanbul',
IntlDateFormatter::GREGORIAN);
echo
"\nİkinci biçemli çıktı: ".$fmt->format(1234567890);

$fmt = new IntlDateFormatter("tr_TR", IntlDateFormatter::FULL,
IntlDateFormatter::FULL,'Europe/Istanbul',
IntlDateFormatter::GREGORIAN, "dd/MM/yyyy");
echo
"\nİlk kalıbın çıktısı: ".$fmt->format(1234567890);
$fmt = new IntlDateFormatter("en-US", IntlDateFormatter::FULL,
IntlDateFormatter::FULL, 'Europe/Istanbul',
IntlDateFormatter::GREGORIAN, "MM/dd/yyyy");
echo
"\nİkinci kalıbın çıktısı: ".$fmt->format(1234567890);
?>

Yukarıdaki örneğin çıktısı:

İlk biçemli çıktı: 14 Şubat 2009 Cumartesi 01:31:30 Doğu Avrupa Standart Saati
İkinci biçemli çıktı: Saturday, February 14, 2009 at 1:31:30 AM Eastern European Standard Time
İlk kalıbın çıktısı: 14/02/2009
İkinci kalıbın çıktısı: 02/14/2009

Ayrıca Bakınız

add a note

User Contributed Notes 5 notes

up
3
daniel dot rhodes at warpasylum dot co dot uk
12 years ago
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]
?>
up
2
mikko dot rantalainen at peda dot net
11 years ago
Documentation says "timezone: Time zone ID, default is system default."

The "system default" really means only the "TZ" environment variable on Unix/Linux systems. It does not mean PHP ini setting or value set via date_default_timezone_set() or the OS default time zone in file "/etc/timezone".
up
1
info at mobger dot de
1 year ago
The $locale can although contain the information about the calendar

<?php
//...
$traditionalFormatter = new IntlDateFormatter(
$locale.'@calendar='.$calendar,
IntlDateFormatter::SHORT,
IntlDateFormatter::SHORT,
'Europe/Berlin',
IntlDateFormatter::TRADITIONAL,
'yyyy/MM/dd HH:mm:ss' // ICU-datetime-format
);
//..
?>

To get the allowed values for $calendar, use the following code:

<?php
$bundle
=new ResourceBundle('','ICUDATA');
$cnames=[];
$calendars=$bundle->get('calendar');
foreach(
$calendars as $n=>$v){
$cnames[]=$n;
}
echo (
print_r($cnames,true));

?>

The result is:
Array
(
[0] => buddhist
[1] => chinese
[2] => coptic
[3] => dangi
[4] => default
[5] => ethiopic
[6] => ethiopic-amete-alem
[7] => gregorian
[8] => hebrew
[9] => indian
[10] => islamic
[11] => islamic-civil
[12] => japanese
[13] => persian
[14] => roc
)
up
1
Anonymous
5 years ago
The documentation says that $datetype and $timetype can also be NULL, in which case ICUʼs default date type or time type will be used.

But when declare (strict_types=1); is also set, Intl fails to create the IntlDateFormatter class, and it returns an error "datefmt_create: unable to parse input parameters".
up
0
Patanjali
2 years ago
Just to be clear, to use any non-gregorian calendar:

a. The locale must be in the form of locale@calendar=calendar-name

b. The calendar must use the intlDateFormatter::TRADITIONAL constant, or an intlCalendar object created with a locale as specified in a.

The calendar name can be 'gregorian', even if the intlDateFormatter::TRADITIONAL constant is used, which makes for a more generic code approach.
To Top