';
echo "Local = " . $datetime;
$given = new DateTime($datetime, new DateTimeZone($timezoneStr));
// check if $given was adjusted for daylight savings in locale
if ($given->format('Y-m-d H:i:s') != $datetime)
{
print '
';
echo "WARNING: $datetime is impossible in $timezoneStr. Automatically adjusted to account for daylight savings time.";
}
$given->setTimezone(new DateTimeZone("UTC"));
$output = $given->format("Y-m-d H:i:s");
print '
';
echo "UTC = " . $output;
$ano = substr($output, 0, 4);
$mes = substr($output, 5, 2);
$dia = substr($output, 8, 2);
$hor = substr($output, 11, 2);
$min = substr($output, 14, 2);
$sec = substr($output, 17, 2);
print '
';
echo "Year = " . $ano;
print '
';
echo "Month = " . $mes;
print '
';
echo "Day = " . $dia;
print '
';
echo "Hours = " . $hor;
print '
';
echo "Minutes = " . $min;
print '
';
echo "Seconds = " . $sec;
$meses = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"];
$mesStr = $meses[intval($mes) - 1];
print '
';
echo "UTC = ". $dia . "-" . $mesStr . "-" . $ano . " a las " . $hor . ":" . $min . ":" . $sec;
$secondsInTime = intval($hor * 3600) - intval(12 * 3600) + intval($min * 60) + intval($sec);
$secondsInTimeDec = $secondsInTime / 86400;
$jd = GregorianToJD($mes, $dia, $ano);
$jdDec = intval($jd) + $secondsInTimeDec;
print '
';
echo "JulianDay = " . $jdDec;
return $jdDec;
}
function GetTimeZoneOffset($tz, $jd)
{
$timezone_identifiers = DateTimeZone::listIdentifiers();
for ($i=0; $i < 1005; $i++)
{
if ($timezone_identifiers[$i] == "")
break;
else if ($timezone_identifiers[$i] == $tz)
{
$timezone = new DateTimeZone($timezone_identifiers[$i]);
$transitions = $timezone->getTransitions();
for ($k=0; $k<500; $k++)
{
if ($transitions[$k] == "")
break;
$UnixTimeStamp = $transitions[$k][ts];
$julianDay = ($UnixTimeStamp / 86400) + 2440587.5;
if ($julianDay > $jd)
return $offsetPrev;
$offsetPrev = $transitions[$k][offset];
}
return;
}
}
return;
}
$dt1 = "2024-10-27 02:30:00";
$tzName = $timezoneStr;
$jd1 = CalcDatetimeFromTz($dt1, $tzName);
$offsetDtTmTz = GetTimeZoneOffset($tzName, $jd1);
print '
';
print '
';
echo "Offset = " . $offsetDtTmTz;
$dateinsec=strtotime($dt1);
$newdate=$dateinsec-$offsetDtTmTz;
print '
';
$dt2 = date('Y-m-d H:i:s',$newdate);
echo "New Date Minus Offset = " . $dt2;
$NewJulianDayMinusOffset = $jd1 - ($offsetDtTmTz / 86400);
print '
';
echo "New JulianDay Minus Offset = " . $NewJulianDayMinusOffset;
print '
';
print '
';
$jd2 = CalcDatetimeFromTz($dt2, $tzName);
if ($jd2 != $NewJulianDayMinusOffset)
{
print '
';
print '
';
echo "WARNING:";
print '
';
echo 'The LOCAL Date/Time "' . $dt1 . '" for the TimeZone "' . $tzName . '"';
print '
';
echo "Corresponds to a Time Change in which There are 2 Possible Hours";
print '
';
echo "One Before the Change, and Other After the Change";
}
?>