Prev | Current Page 402 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"


336 CHAPTER 12 ?–  D ATE AND TIME
Suppose you are working with monetary values and want to ensure that the sums
are formatted according to the Italian locale:
setlocale(LC_MONETARY, "it_IT");
echo money_format("%i", 478.54);
This returns the following:
EUR 478,54
To localize dates and times, you need to use setlocale() in conjunction with
strftime(), introduced next.
Localizing Dates and Times
The strftime() function formats a date and time according to the localization setting
as specified by setlocale(). Its prototype follows:
string strftime(string format [, int timestamp])
strftime()??™s behavior is quite similar to the date()function, accepting conversion
parameters that determine the layout of the requested date and time. However, the
parameters are different from those used by date(), necessitating reproduction of all
available parameters, shown in Table 12-2 for your reference. Keep in mind that all
parameters will produce the output according to the set locale. Also note that some of
these parameters aren??™t supported on Windows.
Table 12-2. The strftime() Function??™s Format Parameters
Parameter Description Examples or Range
%a Abbreviated weekly name Mon, Tue
%A Complete weekday name Monday, Tuesday
%b Abbreviated month name Jan, Feb
%B Complete month name January, February
%c Standard date and time 04/26/07 21:40:46
%C Century number 21
%d Numerical day of month, with leading zero 01, 15, 26
%D Equivalent to %m/%d/%y 04/26/07
CHAPTER 1 2 ?–  D ATE AND T IME 337
%e Numerical day of month, no leading zero 26
%g Same output as %G, but without the century 05
%G Numerical year, behaving according to rules set by %V 2007
%h Same output as %b Jan, Feb
%H Numerical hour (24-hour clock), with leading zero 00 through 23
%I Numerical hour (12-hour clock), with leading zero 01 through 12
%j Numerical day of year 001 through 366
%m Numerical month, with leading zero 01 through 12
%M Numerical minute, with leading zero 00 through 59
%n Newline character \n
%p Ante meridiem and post meridiem AM, PM
%r Ante meridiem and post meridiem, with periods A.


Pages:
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414