Last active
January 4, 2016 12:19
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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