本月开始和结束的时间戳 [英] Timestamps of start and end of month

查看:104
本文介绍了本月开始和结束的时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用PHP获取每个月的第一分钟和最后一分钟的时间戳?

How can one get the timestamps of the first and last minutes of any month using PHP?

推荐答案

您可以使用 mktime date :

$first_minute = mktime(0, 0, 0, date("n"), 1);
$last_minute = mktime(23, 59, 59, date("n"), date("t"));

那是当前月份.如果要在任何月份使用它,则可以相应地更改month和day参数.

That is for the current month. If you want to have it for any month, you have change the month and day parameter accordingly.

如果要每月生成一次,则可以循环:

If you want to generate it for every month, you can just loop:

$times  = array();
for($month = 1; $month <= 12; $month++) {
    $first_minute = mktime(0, 0, 0, $month, 1);
    $last_minute = mktime(23, 59, 59, $month, date('t', $first_minute));
    $times[$month] = array($first_minute, $last_minute);
}

演示

这篇关于本月开始和结束的时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆