微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PHP 获取指定日期区间天数不重复的日期或者时间戳

function getDaterange($dateStart,$dateEnd,bool $timestamp=false): array
{
    $dateStartTimeStamp = strtotime($dateStart);
    $dateEndTimeStamp = strtotime($dateEnd);
    $createTime = [];
    $createTimeDate = [];
    for ($i = $dateStartTimeStamp; $i <= $dateEndTimeStamp; $i+=86400) {
        $createTimestamp = $i + mt_rand(0, 86400);
        $createTime[] = $createTimestamp;
        $createTimeDate[] = date('Y-m-d H:i:s', $createTimestamp);
    }
    return $timestamp ? $createTime : $createTimeDate;
}
print_r(getDaterange('2022-02-05', '2022-03-5'));

Array
(
[0] => 2022-02-25 22:58:55
[1] => 2022-02-26 11:10:42
[2] => 2022-02-27 16:04:41
[3] => 2022-02-28 16:44:26
[4] => 2022-03-01 17:01:27
[5] => 2022-03-02 06:01:14
[6] => 2022-03-03 18:20:22
[7] => 2022-03-04 18:37:29
[8] => 2022-03-05 15:17:45
)

Process finished with exit code 0

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐