I am trying to output dates in the Italian format using date() as follows:
After a lot of attempts, this is the solution works like charm:
STEP 1: We will set the localization and time zone (upper page)
// ====> Localizzazione
setlocale(LC_TIME, 'ita', 'it_IT'); // Italiano
date_default_timezone_set("Europe/Rome"); // Ora
STEP 2: We make a function for easily convert when we need (wherever into page)
//=============== Funzione formattazione data
function f_date_time($f_date, $f_date_info) {
if (strlen($f_date) > 7){
$dateToParse = $f_date;
}else{
$dateToParse = date("YmdHis");
}
switch ($f_date_info) {
case 1: //20191130
echo date("Ymd");
break;
case 2: //30/11/19
echo utf8_encode(strftime('%d/%m/%y', strtotime($dateToParse)));
break;
case 3: //30/11/2019
echo utf8_encode(strftime('%d/%m/%Y', strtotime($dateToParse)));
break;
case 4: //30/11/2019 15:27:50
echo utf8_encode(strftime('%d/%m/%Y %H:%M:%S', strtotime($dateToParse)));
break;
case 5: //Saturday 30
echo utf8_encode(strftime('%A %d', strtotime($dateToParse)));
break;
case 6: //Saturday 30 November
echo utf8_encode(strftime('%A %d %B', strtotime($dateToParse)));
break;
case 7: //Saturday 30 November 2019
echo utf8_encode(strftime('%A %d %B %Y', strtotime($dateToParse)));
break;
case 8: //Saturday 30 November 2019 ore 15:27:50
echo utf8_encode(strftime('%A %d %B %Y %H:%M:%S', strtotime($dateToParse)));
break;
default: //20191130152750
echo date("YmdHis");;
}
}
STEP 3: Now to convert your data just use the function (wherever into your code)
$today = "20190320234500"; //Format yyyymmddhhmmss
echo f_date_time($today, 1) . "\n";
echo f_date_time($today, 2) . "\n";
echo f_date_time($today, 3) . "\n";
echo f_date_time($today, 4) . "\n";
echo f_date_time($today, 5) . "\n";
echo f_date_time($today, 6) . "\n";
echo f_date_time($today, 7) . "\n";
echo f_date_time($today, 8) . "\n";
OUTPUT: will be somethink like this:
20191231
20/03/74
20/03/1974
20/03/1974 23:45:00
mercoledì 20
mercoledì 20 marzo
mercoledì 20 marzo 1974
mercoledì 20 marzo 1974 23:45:00
PS: happy birday to me :-)