php carbon 检查现在是否在两次之间(晚上 10 点到早上 8 点) [英] php carbon check if now is between two times (10pm-8am)

查看:55
本文介绍了php carbon 检查现在是否在两次之间(晚上 10 点到早上 8 点)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$start = '22:00:00';
$end = '08:00:00';
$now = Carbon::now('UTC');

如何查看$now的时间是否在时间范围内?

How can I check if the time of $now is within the timerange?

推荐答案

使用 Carbon 有多种方法可以实现这一点.最简单的方法之一是使用 createFromTimeStringbetween 方法:

There are several ways to achieve that by using Carbon. One of the easiest ways is using createFromTimeString and between methods:

$now = Carbon::now();

$start = Carbon::createFromTimeString('22:00');
$end = Carbon::createFromTimeString('08:00')->addDay();

if ($now->between($start, $end)) {
    // ¯\_(ツ)_/¯
}

这篇关于php carbon 检查现在是否在两次之间(晚上 10 点到早上 8 点)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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