如何反转 PHP 中的 mktime() 函数?

发布于 2024-09-30 07:51:38 字数 151 浏览 1 评论 0原文

我正在使用以下方法将时间转换为整数

mktime(hour,min,second,month,day,year)

我如何反转它以获得所需的日期?目前我不需要分钟或秒,所以我使用零“0”。任何建议将不胜感激。

谢谢。

I am using following to convert time to integer

mktime(hour,minute,second,month,day,year)

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浮生未歇 2024-10-07 07:51:38

使用函数 date()

$yourtime = mktime(...);
date("d/m/Y h", $yourtime);

Use the function date()

$yourtime = mktime(...);
date("d/m/Y h", $yourtime);
枕梦 2024-10-07 07:51:38

如果您的数据来自 HTML 表单,您可以使用它代替 mktime():

$time = strtotime($_GET['time']);
$rounded = $time - $time % 3600; // rounds down to the last hour

然后只需使用:

date ('Y-m-d',$rounded);

显示日期。

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.

别想她 2024-10-07 07:51:38

您可能正在寻找 getdate(),它返回包含秒、分钟、小时等的关联数组。

// 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’]);

如果失败,您可能需要查看 idate() 返回与 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文