PHP - 如何使用 $timestamp 检查今天是星期一还是本月的第一天? [英] PHP - how to use $timestamp to check if today is Monday or 1st of the month?

查看:17
本文介绍了PHP - 如何使用 $timestamp 检查今天是星期一还是本月的第一天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在网上浏览示例,我发现它们有点神秘或矫枉过正.

I have been looking through examples online, and I am finding them a bit cryptic or overkill.

我需要做的是这样的:

$timestamp = time();

然后找出这一天是星期一还是月初?

and then find out if the day is a Monday or a fist of the month?

我确信这是可能的,我只是不知道该怎么做.

I am sure it is possible, I am just not sure how to do that.

推荐答案

其实你不需要时间戳变量,因为:

Actually, you don't need timestamp variable because:

摘自date函数的php.net:

Exerpt from date function of php.net:

返回根据给定格式字符串格式化的字符串给定的整数时间戳或当前时间(如果没有时间戳)给定的.换句话说,timestamp 是可选的,默认为该值时间().

Returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given. In other words, timestamp is optional and defaults to the value of time().

if(date('j', $timestamp) === '1') 
    echo "It is the first day of the month today
";

if(date('D', $timestamp) === 'Mon') 
    echo "It is Monday today
";

这篇关于PHP - 如何使用 $timestamp 检查今天是星期一还是本月的第一天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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