Preview:
<?php
// Esempio di chiamata cURL che ritorna un JSON con un timestamp
$curl = curl_init("https://esempio.com/api/data"); // Cambia con la tua URL
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
curl_close($curl);

// Decodifica JSON (supponiamo che abbia un campo 'timestamp')
$data = json_decode($response, true);
$remoteTimestamp = isset($data['timestamp']) ? (int)$data['timestamp'] : null;

if ($remoteTimestamp === null) {
    die("Timestamp non trovato nella risposta");
}

// Crea oggetto DateTime dal timestamp ricevuto
$remoteDate = (new DateTime())->setTimestamp($remoteTimestamp);

// Crea oggetto DateTime per 1 anno fa a mezzanotte
$localDate = new DateTime();
$localDate->modify('-1 year')->setTime(0, 0, 0);

// Confronto
if ($remoteDate < $localDate) {
    echo "Il timestamp remoto è più vecchio di 1 anno.\n";
} else {
    echo "Il timestamp remoto è più recente di 1 anno.\n";
}

// Debug: stampa date
echo "Data remota: " . $remoteDate->format('Y-m-d H:i:s') . "\n";
echo "Data di riferimento: " . $localDate->format('Y-m-d H:i:s') . "\n";
?>
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter