Prev | Current Page 335 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

Let??™s start by
looking at normalizing dates because, like numbers, different regions of the world write their dates in
difference formats and obviously, use their local language for the names of the months and days of the week.
Consider, the date 2nd March 2007. In the UK, this may be written as 2/3/1007 whereas in the USA it
would be writer 3/2/2007. To use the date supplied by our users, we need to normalize it and getDate() is the
function to use as shown in listing 14.3..
Licensed to Menshu You
Zend Framework in Action (Ch01) Manning Publications Co. 38
Listing 14.3: Date normalization with Zend_Locale
$locale = new Zend_Locale('en_US'); A
$date = Zend_Locale_Format::getDate('3/2/2007',
array('locale' => $locale));
print $date['month']; B
A USA locale
B Prints ???3??? for March
As usual, we create a locale object for the correct language and region and then us it with the getDate()
function. We have used the en_US locale for the USA and so getDate() correctly determines that the month is
March. If we changed the locale to en_GB, then the month would be February. Similarly, we can use
checkDateFormat() to ensure that the date string received is valid for the locale and obviously, once we have
the date information separated into its components, we can manipulate it in any way we like.


Pages:
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
Pozycjonowanie galanteria hotelowa noclegi darłowo Odżywki projektowanie budynków mieszkalnych