Mysql
 sql >> Base de données >  >> RDS >> Mysql

Une autre question dateTime

Pourquoi ne pas simplement le convertir en UTC ?

    $datetime = "2010-01-19 00:00:00";
    echo "Datetime Before: ".$datetime."<br />";
    $dttostr = strtotime("2010-01-19 00:00:00");
    echo "Datetime After: ".formatToUTC($dttostr)."<br />";
    echo "System Timezone: ".date_default_timezone_get()."<br />";

    function formatToUTC($passeddt) {
        // Get the default timezone
        $default_tz = date_default_timezone_get();

        // Set timezone to UTC
        date_default_timezone_set("UTC");

        // convert datetime into UTC
        $utc_format = date("Y-m-d\TG:i:s\Z", $passeddt);

        // Might not need to set back to the default but did just in case
        date_default_timezone_set($default_tz);

        return $utc_format;
    }