replace of php mktime

replace of php mktime

by Francis 2014-09-23 13:16:00

Why we replace of php mktime used?
Because the mktime function year range limit is 1970 to 2037 (Unix timestamp).
Following function no year limits.
<?php
function mod($x,$y) { return ($x-(floor($x/$y)*$y)); }

function mymktime($hour, $minute, $sec, $month, $day, $year)
{
   return ($hour * 3600 + $minute * 60 + $sec) +
               ($day * 86400 + $month * 2592000 + $year * 31104000);
}

function mydate($time,$format)
{
   $format = ereg_replace("([DMYhms])","$\1",$format);
   $Y = floor($time / 31104000);
   $rest = mod($time, 31104000);
   $M = floor($rest / 2592000);
   $rest = mod($rest, 2592000);
   $D = floor($rest / 86400);
   $rest = mod($rest, 86400);
   $h = floor($rest / 3600);
   $rest = mod($rest, 3600);
   $m = floor($rest / 60);
   $s = mod($rest, 60);
   eval("$res = "$format";");
   return $res;
}

$mtime = mymktime(0, 0, 0, 7, 1, 2000);
echo mydate($mtime, "D-M-Y h:m:s");
?>

1108
like
0
dislike
0
mail
flag

You must LOGIN to add comments