how to reverse mktime() function in PHP?
I am using following to convert time to integer
mktime(hour,minute,second,month,day,yea开发者_运维问答r)
How would I reverse this to get desired Date? Currently I do not need Minutes or Seconds so I am using Zeroes '0' for them. Any suggestions would be appreciated.
Thanks.
Use the function date()
$yourtime = mktime(...);
date("d/m/Y h", $yourtime);
If your data came from an HTML form, you can use this instead of mktime():
$time = strtotime($_GET['time']);
$rounded = $time - $time % 3600; // rounds down to the last hour
Then just use:
date ('Y-m-d',$rounded);
to display the date.
You might be looking for getdate()
, it returns associative array with seconds, minutes, hours, etc.
// make some time value
$time = time();
// get date components
$d = getdate($time);
// make a new time value with time values reset
$time = mktime(0, 0, 0, $d[‘mon’], $d[‘mday’], $d[‘year’]);
Failing that you might want to look at idate()
which returns the same values as date()
but as an integer instead of string which might perform better in case you don’t actually want strings.
精彩评论