PHP - how to use $timestamp to check if today is Monday or 1st of the month?(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 检查今天是星期一还是本月的第一天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP - 如何使用 $timestamp 检查今天是星期一还是本月的第一天?


基础教程推荐
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 在多维数组中查找最大值 2021-01-01