Date and time in Greek
I tried to find the same but couldn't find a complete solution as I needed it. In my case, I need to write the published date and time of the article in Greek, for example Αναρτήθηκε Σάββατο 2 Μαΐου 2015
.
So, using some response code costastg
, I managed to put together the following function.
I'm sure there are other solutions as well:
function formatToGreekDate($date){
//Expected date format yyyy-mm-dd hh:MM:ss
$greekMonths = array('Ιανουαρίου','Φεβρουαρίου','Μαρτίου','Απριλίου','Μαΐου','Ιουνίου','Ιουλίου','Αυγούστου','Σεπτεμβρίου','Οκτωβρίου','Νοεμβρίου','Δεκεμβρίου');
$greekdays = array('Δευτέρα','Τρίτη','Τετάρτη','Πέμπτη','Παρασκευή','Σάββατο','Κυριακή');
$time = strtotime($date);
$newformat = date('Y-m-d',$time);
return $greekdays[date('N', strtotime($newformat))-1].' '. date('j', strtotime($newformat)).' '.$greekMonths[date('m', strtotime($newformat))-1]. ' '. date('Y', strtotime($newformat)); // . ' '. $date;
}
source to share
Full answer:
date_default_timezone_set('Europe/Athens');
setlocale(LC_TIME, 'el_GR.UTF-8');
echo strftime('%A ');
$greekMonths = array('Ιανουαρίου','Φεβρουαρίου','Μαρτίου','Απριλίου','Μαΐου','Ιουνίου','Ιουλίου','Αυγούστου','Σεπτεμβρίου','Οκτωβρίου','Νοεμβρίου','Δεκεμβρίου');
$greekDate = date('j') . ' ' . $greekMonths[intval(date('m'))-1] . ' ' . date('Y');
echo $greekDate;
this will display the date as:
Πέμπτη 4 Φεβρουαρίου 2013
UPDATE: For the above block to work, it is very important to install the Greek language in PHP.
This is an alternative:
date_default_timezone_set('Europe/Athens');
setlocale(LC_TIME, 'el_GR.UTF-8');
$day = date("w");
$greekDays = array( "Κυριακή", "Δευτέρα", "Τρίτη", "Τετάρτη", "Πέμπτη", "Παρασκευή", "Σάββατο" );
$greekMonths = array('Ιανουαρίου','Φεβρουαρίου','Μαρτίου','Απριλίου','Μαΐου','Ιουνίου','Ιουλίου','Αυγούστου','Σεπτεμβρίου','Οκτωβρίου','Νοεμβρίου','Δεκεμβρίου');
$greekDate = $greekDays[$day] . ' ' . date('j') . ' ' . $greekMonths[intval(date('m'))-1] . ' ' . date('Y');
echo $greekDate;
source to share
You have to use setlocale and strftime, example to get the idea:
setlocale(LC_TIME, 'el_GR.UTF-8');
// Your display formatting from https://www.php.net/manual/en/function.strftime.php
$field_date_format = '%A, %d %B, %Y';
// Will display= Greek: Πέμπτη, 14 Φεβρουάριος, 2013
echo "Greek: ".strftime($field_date_format, strtotime("14-02-2013"));
I know that "Φεβρουάριος" is not "Φεβρουάριου", but if it is not critical to your needs, you can use this.
source to share
You should have everything you need using date :
$greekMonths = [
'Ianouarios', 'Fevrouarios', 'Martios', 'Aprilios', 'Maios',
'Iounios', 'Ioulios', 'Avgoustos', 'Septemvrios', 'Oktovrios',
'Noemvrios', 'Dekemvrios'
];
$greekDate = date('d') . ' ' . $greekMonths[intval(date('m'))-1] . ' ' . date('Y');
echo $greekDate;
Second way using setlocale :
setlocale(LC_CTYPE, 'greek');
setlocale(LC_TIME, 'greek');
source to share
If I am correct you want to display the parameter l
in Greek. You must set the PHP locale to Greek.
Use setlocale()
: http://php.net/manual/en/function.setlocale.php
setlocale(LC_TIME, 'greek');
source to share