Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date and time in Greek

I'm currently using a website to get the time in Athens:

$d = new DateTime("now", new DateTimeZone("Europe/Athens"));
echo $d->format("l, d M Y");

But I would like the date to be displayed in Greek and in the same format.

like image 697
Meserlian Avatar asked Feb 14 '13 10:02

Meserlian


People also ask

How do Greeks write the date?

Dates written in Greek typically follow this format: [day] [month] [year].

Do Greeks use 24hr clock?

In Greece the all-numeric form for dates is in the little endianness order of "day month year". Years can be written with 2 or 4 digits. For example, either 24/5/2004 or 24/5/04. The 12-hour notation is used in verbal communication, but the 24-hour format is also used along with the 12-hour notation in writing.


2 Answers

The 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 like:

Πέμπτη 4 Φεβρουαρίου 2013

UPDATE: For the above chunk to work it is very important to set your PHP locale to Greek.

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;
like image 190
costastg Avatar answered Sep 19 '22 23:09

costastg


I was in the quest to find the same thing but I didn't find a full solution as I needed it. In my case I need to write the posted datetime of the article in Greek like Αναρτήθηκε Σάββατο 2 Μαΐου 2015.

So using some code of costastg answer, I managed to put together the following function.

I am sure there are other solutions out there:

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;
}
like image 37
themhz Avatar answered Sep 19 '22 23:09

themhz