如何在某个时间段内执行if语句 [英] How to perform if statement for a certain timeperiod

查看:339
本文介绍了如何在某个时间段内执行if语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在星期一上午10:00到星期六上午10:00之间在PHP中执行某些任务,我想在星期六上午10:30到星期一上午10点之间执行其他任务。 每周。

I want to perform certain tasks in PHP between Monday 10:00am till Saturday 10:00am and I want to perform other tasks between Saturday 10:30am till Monday 10am. Every week.

如果这是一个愚蠢的问题,我很抱歉。任何帮助都将受到高度赞赏。

I am sorry if that's a silly question. Any help would be highly appreciated.

推荐答案

如果您正在运行时间触发的任务运行一个cron作业或者它是一个用户触发像网站,你想要根据日期更改页面然后使用if else语句来选择任务。

if you are running a time triggered task run a cron job or if it is a user triggered like website and you want to change page according to day then use if else statement to select task.

你可以在工作日和小时获得时间:分钟::秒用于if else选择使用这个

you can get the time in weekday and hour:minute::second for if else selection using this

$d = new DateTime('Sunday,23:23:48 ');  //set time  day time format
echo $d->format('l , H:i:s ');

$date = new DateTime();   // get current datetime

echo $date->format('l , H:i:s ');   //php get time in day time format

//output example  Sunday , 23:23:48 Sunday , 23:34:47

这篇关于如何在某个时间段内执行if语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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