开发者

how to reverse mktime() function in PHP?

开发者 https://www.devze.com 2023-01-23 07:09 出处:网络
I am using following to convert time to integer mktime(hour,minute,second,month,day,yea开发者_运维问答r)

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消