note 108019 added to class.datetime

From: Date: Thu, 22 Mar 2012 18:22:38 +0000
Subject: note 108019 added to class.datetime
Groups: php.notes 
Request: Send a blank email to php-notes+get-186775@lists.php.net to get a copy of this message
DateTime class does not use locales so here I test and compare its formating with strftime() function's one: <?php // Under UNIX, command "$ locale -a" should provide you with your server's options. $data_do_mysql = "2011-09-29 23:50:26"; echo '<strong>' . "\$data_do_mysql" . '</strong>' . ":" . $data_do_mysql . "." . '<br />' . '<br />'; $dataInicial = new DateTime(trim($data_do_mysql)); // setlocale() used with strftime(). $meu_locale = setlocale(LC_ALL, "pt_BR.utf8"); $data_inicial = strftime("%d de %b de %Y", strtotime(trim($data_do_mysql))); // Outputs: // $data_do_mysql formatada com a classe DateTime:29-Sep-2011. echo '<strong>' . "\$data_do_mysql" . '</strong>' . " formatada com a classe DateTime:" . $dataInicial->format('d-M-Y') . "." . '<br />' . '<br />'; // Outputs: // $data_do_mysql formatada com a função strftime():29 de Set de 2011. echo '<strong>' . "\$data_do_mysql" . '</strong>' . " formatada com a fun&ccedil;&atilde;o strftime():" . $data_inicial . "." . '<br />' . '<br />'; // setlocale() fails :-( if (!$meu_locale) { echo "Prefiro usar DateTime."; } // Yay setlocale() :-D else { echo "Prefiro usar strftime()."; } exit(); ?> ---- Server IP: 69.147.83.197 Probable Submitter: 201.13.209.104 ---- Manual Page -- http://www.php.net/manual/en/class.datetime.php Edit -- https://master.php.net/note/edit/108019 Del: integrated -- https://master.php.net/note/delete/108019/integrated Del: useless -- https://master.php.net/note/delete/108019/useless Del: bad code -- https://master.php.net/note/delete/108019/bad+code Del: spam -- https://master.php.net/note/delete/108019/spam Del: non-english -- https://master.php.net/note/delete/108019/non-english Del: in docs -- https://master.php.net/note/delete/108019/in+docs Del: other reasons-- https://master.php.net/note/delete/108019 Reject -- https://master.php.net/note/reject/108019 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#186775) next »