Reputation: 327
Hello i have 2 variables for month and year. I would like to display month name in my language but i dont manage to make it working. Here is my code
setlocale(LC_TIME, array('ro.utf-8', 'ro_RO.UTF-8', 'ro_RO.utf-8', 'ro', 'ro_RO', 'ro_RO.ISO8859-2'));
$luna=$_GET['month'];
$an=$_GET['year'];
$dateObj = DateTime::createFromFormat('!m', $luna);
$monthName = $dateObj->format('F');
$data='Arhiva '.$monthName.' - '.$an.'';
it displays June 2014 and i want Iunie 2014 June=Iunie in my country. The month given by link is dinamic and it can be any number.
Upvotes: 4
Views: 6248
Reputation: 10717
You can convert with IntlDateFormatter function
$dateObj = DateTime::createFromFormat('!m', $luna);
$formatter = new IntlDateFormatter("ro_RO",
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'Europe/Bucharest',
IntlDateFormatter::GREGORIAN,
'MMMM');
echo $formatter->format($dateObj).' - '.$an; // Iunie - 2014
Upvotes: 3
Reputation: 2030
Try This
setlocale(LC_TIME, 'fr_FR');
$monthName = strftime("%B",mktime(0, 0, 0, $_GET['month']));
echo $monthName ; //It outputs month name in your local language that you have set in 'setlocale'
In this case it is set to French. Similarly you can use it for your locale by passing your language code like:
sr_BA - Serbian (Montenegro);
sr_CS - Serbian (Serbia);
sr_ME - Serbian (Serbia and Montenegro);
Happy coding!!
Upvotes: 0
Reputation: 3289
You can use strftime
(http://php.net/manual/en/function.strftime.php):
setlocale(LC_TIME, array('ro.utf-8', 'ro_RO.UTF-8', 'ro_RO.utf-8', 'ro', 'ro_RO', 'ro_RO.ISO8859-2'));
$luna=$_GET['month'];
$an=$_GET['year'];
$dateObj = DateTime::createFromFormat('!m', $luna);
$monthName = strftime('%B', $dateObj->getTimestamp());
$data='Arhiva '.$monthName.' - '.$an.'';
Upvotes: 3