Modifica da array a oggetto ->
Codice PHP:
$timezone = local_timezone();
$utc_ora = (float) moment_utc(moment_now($timezone));
$ora = moment_tz($utc_ora);
$utc_oggi = (float) moment_utc(moment_today($timezone));
$oggi = moment_tz($utc_oggi);
//ora locale
$ora_locale = local_now($timezone);
echo 'Sono le ore ' . $ora_locale;
$start = strlen(ltrim($row['start'], '+-')) > 4 ? $row['start'].' 00:00:00' : varchar_four_year($row['start']).'-01-01 00:00:00';
$end = (strlen(ltrim($row['end'], '+-')) > 4 ? $row['end'].' 00:00:00' : ($row['end'] ? varchar_four_year($row['end']).'-01-01 00:00:00' : ($row['died'] ? $row['died'].' 00:00:00' : $ora)));
if($row['died'] && ($row['died'].' 00:00:00') == $end) {
echo 'fine carriera';
} elseif($ora == $end) {
echo 'carriera in corso';
} else {
echo 'abbandono carriera';
}
$film_now = '';
if($row){
$local_release = $row['release_data'];
$local_data = $row['year'];
}
//puoi anche creare un file funzioni.php e usi include o require per queste funzioni
function varchar_four_year($varchar) {
$year = ltrim($varchar, '+');
$sign = (isset($year[0]) ? ($year[0] == '-' ? '-' : '') : '');
$year = (int) ltrim($year, '-');
$year_four = sprintf('%s%04d', $sign, $year);
return $year_four;
}
function moment_tz($tz_utc) {
$now = date_create('@'.$tz_utc);
$display = ($now->format('Y-m-d H:i:s'));
return $display;
}
function local_now($tz) {
$now = (moment_now($tz)->format('Y-m-d H:i:s'));
return $now;
}
function moment_now($tz) {
$now = date_create('now', $tz);
return $now;
}
function local_today($tz) {
$today = (moment_today($tz)->format('Y-m-d H:i:s'));
return $today;
}
function moment_today($tz) {
$today = date_create('today', $tz);
return $today;
}
function moment_utc($moment_obj) {
$moment_tm = ($moment_obj->format('U'));
return $moment_tm;
}
function local_timezone() {
$tz_local = timezone_open('Europe/Moscow');
return $tz_local;
}
//dopo endwhile
if(!$row && ($local_release || $local_data)) {
//differenza film dall'inizio carriera di un'attore
$release_data = $local_release ? $local_release.' 00:00:00' : varchar_four_year($local_data).'-01-01 00:00:00';
$sign = $release_data[0] == '-' ? '-' : '';
$release_data = ltrim($release_data, '-');
if(!(intval(substr($release_data, 0, 4)) && intval(substr($release_data, 5, 2)) && intval(substr($release_data, 8, 2)))) {
$film_now = 'data non valida';
} else {
$diff_film = date_create($sign.$release_data, new DateTimeZone('UTC'))->diff(date_create($start, new DateTimeZone('UTC')));
$testo = 'differenza film inzio carriera';
$year_film = $diff_film->y;
$mese_film = $diff_film->m;
$giorni_film = $diff_film->d;
if($year_film) {
$film_now = $year_film.' years';
} elseif($mese_film == 0 && $giorni_film == 0) {
$film_now = 'anno corrente';
} elseif($mese_film) {
$film_now = $mese_film.' months';
if($giorni_film) {
$film_now .= ' '.$giorni_film.' days';
}
} else {
$film_now = $giorni_film.' days';
}
}
if($film_now) {
$film_now .= ' '.$testo;
}
}
$film_current = '';
if($film_now && substr($sign.$release_data, 0, 4) == substr($ora, 0, 4)) {
//differenza anno corrente film
$diff_current_year = date_create($sign.$release_data, new DateTimeZone('UTC'))->diff(date_create($oggi, new DateTimeZone('UTC')));
$testo = 'differenza anno corrente';
$year_current = $diff_current_year->y;
$mese_current = $diff_current_year->m;
$giorni_current = $diff_current_year->d;
if($year_current) {
$film_current = $year_current.' years';
} elseif($mese_current == 0 && $giorni_current == 0) {
$film_current = 'anno corrente';
} elseif($mese_current) {
$film_current = $mese_current.' months';
if($giorni_film) {
$film_current .= ' '.$giorni_current.' days';
}
} else {
$film_current = $giorni_current.' days';
}
$film_current .= ' '.$testo;
}
var_dump($film_now, $film_current);
//fine dopo endwhile
inserisci dopo endwhile come dice il commento, ps. l'ora locale sarà iterata e mostrata per quanti sono i film.
Codice Editato.