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:

摘自 php.net 的 date 函数:

Exerpt from date function of php.net:

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

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\n";

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