PHP - 如何使用 $timestamp 检查今天是星期一还是本月的第一天?

2022-01-13 00:00:00 timestamp php

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

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

相关文章