downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

IntlDateFormatter::getCalendar> <IntlDateFormatter::create
[edit] Last updated: Fri, 23 Mar 2012

view this page in

IntlDateFormatter::format

datefmt_format

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

IntlDateFormatter::format -- datefmt_formatTarih/saat değerini bir dizge olarak biçemler

Açıklama

Nesne yönelimli kullanım

string IntlDateFormatter::format ( mixed $değer )

Yordamsal kullanım

string datefmt_format ( IntlDateFormatter $biçemleyici , mixed $değer )

Zaman değerini bir dizge olarak biçemler.

Değiştirgeler

biçemleyici

Biçemleyici nesne.

değer

Biçemlenecek değer. Tamsayı olarak bir Unix zaman damgası (Unix zaman başlangıcından itibaren saniye sayısı) olabileceği gibi bir localtime() dizisi de olabilir.

Dönen Değerler

Bir hata oluşmuşsa FALSE aksi takdirde biçemli dizge.

Örnekler

Örnek 1 - datefmt_format() örneği

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

$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$fmt1234567890);
$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($fmt1234567890);
?>

Ö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 Türkiye Saati
İkinci biçemli çıktı: Saturday, February 14, 2009 1:31:30 AM Turkey 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 add a note User Contributed Notes IntlDateFormatter::format
con at bartrail dot de 07-Oct-2011 04:47
I hope this will save some time for others who have to struggle with different php versions on dev and prod plattform in the future:

when formatting a DateTime object with a *custom pattern*, be sure to use a timestamp to pass at the IntlDateFormatter::format in order to have it working on different php versions:

Example for PHP Version 5.3.5-1ubuntu7.2 (my dev machine):
<?php
$date
= new DateTime();

$dateFormatter = IntlDateFormatter::create(
 
Locale::getDefault(),
 
IntlDateFormatter::NONE,
 
IntlDateFormatter::NONE,
 
date_default_timezone_get(),
 
IntlDateFormatter::GREGORIAN,
 
'EEEE'
);

var_dump($dateFormatter->format($date)); // string(6) "Monday"
?>

Example for PHP Version 5.3.2-1ubuntu4.9 (the prod server):
<?php
// same formatting as above

var_dump($dateFormatter->format($date)); // bool(false)
?>

When using $dateFormatter->format($date->getTimestamp()), you'll always get the formatted and localized string instead of a false.
alex 19-May-2010 11:10
It's important to note that a conversion of timezones will be made from the default timezone (date_default_timezone_set()) and the timezone you passed in the constructor (or datefmt_create()).

If you are inserting the dates into your database as UTC time, make sure to set date_default_timezone_set to UTC as well (or any other timezone, but they need to be the same). Once you call ::format, you will get the converted time.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites