TimeUtils.php
754 Bytes
<?php
class TimeUtils
{
public static function iso2stamp($iso) {
try {
$time = new DateTime($iso);
}
catch (Exception $e) {
$time = new DateTime('1970-01-01T00:00:00Z');
}
$stamp = $time->format('U.u');
unset($time);
return $stamp;
}
public static function stamp2iso($stamp) {
$intStamp = floor($stamp);
$intMilli = round(($stamp-$intStamp)*1000);
$isoDate = new DateTime(date($intStamp));
$isoDate.setTime(date('H',$intStam), date('i',$intStam), date('s',$intStam), $intMilli);
error_log($isoDate);
return $isoDate;
}
}
?>