Globalize your Web Applications: Working with Dates in PHP [con't]
The I18N_DateTime class specializes in the formatting of dates and times in a meaningful way to the end-user. Its main functions are:
- string format([int $timestamp = null], [int $format = null]):
Returns the formatted timestamp according to the specified format (
$format
). The$format
argument takes one of these constants:- I18N_DATETIME_SHORT
- I18N_DATETIME_DEFAULT
- I18N_DATETIME_MEDIUM
- I18N_DATETIME_LONG
- I18N_DATETIME_FULL
- string formatFull([int $timestamp = null]): Returns a fully-formatted timestamp (equivalent to: format($timestamp , I18N_DATETIME_FULL).
- string formatLong([int $timestamp = null]): Returns a long-formatted timestamp (equivalent to: format($timestamp , I18N_DATETIME_LONG).
- string formatShort([int $timestamp = null]): Returns a short-formatted timestamp (equivalent to: format($timestamp , I18N_DATETIME_SHORT).
- string formatDate([int $timestamp = null], [int $format = null]): Returns only the formatted date. If the $format argument is missing the method uses the default format for the current locale.
It also contains some additional convenience methods. They are:
- formatDateFull: Same as formatDate( $timestamp , I18N_DATETIME_FULL ).
- formatDateLong: Same as formatDate( $timestamp , I18N_DATETIME_LONG ).
- formatDateMedium: Same as formatDate( $timestamp , I18N_DATETIME_MEDIUM ).
- formatDateShort: Same as formatDate( $timestamp , I18N_DATETIME_SHORT ).
Here are some examples that demonstrate the above functions:
We'll be concluding PHP date formatting in the next installment by examining time-related functions and custom date formatting.
Rob Gravelle combined his love of programming and music to become a software guru and accomplished guitar player. He created systems that are used by Canada Border Services, CSIS and other Intelligence-related organizations. As a software consultant, Rob has developed Web applications for many businesses and recently created a MooTools version of PHPFreechat for ViziMetrics. Musically, Rob recently embarked on a solo music career, after playing with Ivory Knight since 2000. That band was rated as one Canada's top bands by Brave Words magazine (issue #92) and released two CDs. In 2007, Rob recorded the KNIGHTFALL CD in collaboration with the former Ivory Knight vocalist and legendary guitarist/producer, Jeff Waters of Annihilator fame. A completely FREE high quality MP3 download of his "Ultraviolence" instrumental, is available from his website, www.robgravelle.com. Rob is available for short-term software projects and recording session work. to inquire, but note that, due to the volume of emails received, he cannot respond to every email. Potential jobs and praise receive highest priority!
Original: December 9, 2009