Skip to content

Instantly share code, notes, and snippets.

@cereal-s
Last active January 4, 2016 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cereal-s/8620825 to your computer and use it in GitHub Desktop.
Save cereal-s/8620825 to your computer and use it in GitHub Desktop.
Format localized dates. Requires at least PHP 5.3.0 and the Intl library, the latter can be installed from cli: sudo apt-get install php5-intl
<?php
class Dtime extends IntlDateFormatter
{
private $date;
public function __construct($datetime = '', $pattern = 'd MMMM yyyy HH:mm', $locale = 'it')
{
parent::__construct($locale, IntlDateFormatter::FULL, IntlDateFormatter::FULL);
$this->date = new DateTime($datetime);
parent::setPattern($pattern);
}
public function get()
{
# Instead of ucwords() it is better to use mb_convert_case()
# because it can deal with special characters
return mb_convert_case(parent::format($this->date), MB_CASE_TITLE, "UTF-8");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment