TimeUtils.php
786 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);
// c'est moche mais setTime de php ne prends pas en compte les ms
$strMilli = str_pad(strval($intMilli),3, '0', STR_PAD_LEFT);
$dateIso = date("Y-m-d\TH:i:s",$intStamp).'.'.$strMilli;
return $dateIso;
}
}
?>