php取出上一周星期一的时间
时间: 2023-08-24 22:06:26 浏览: 76
可以使用 PHP 中的 date() 和 strtotime() 函数来实现获取上一周星期一的时间。
以下是获取上一周星期一时间的代码示例:
```php
$lastMonday = date('Y-m-d', strtotime('last Monday', strtotime('-1 week')));
echo $lastMonday;
```
这里使用 strtotime('-1 week') 获取当前时间减去一周的时间,然后再使用 strtotime('last Monday') 获取上一个星期一的时间,最后使用 date() 函数将其格式化为所需的日期格式。
输出结果为类似于 "2022-01-10" 的日期字符串。
相关问题
php取出上一周星期天的时间
可以使用 PHP 中的 date() 和 strtotime() 函数来实现获取上一周星期天的时间。
以下是获取上一周星期天时间的代码示例:
```php
$lastSunday = date('Y-m-d', strtotime('last Sunday', strtotime('-1 week')));
echo $lastSunday;
```
这里使用 strtotime('-1 week') 获取当前时间减去一周的时间,然后再使用 strtotime('last Sunday') 获取上一个星期天的时间,最后使用 date() 函数将其格式化为所需的日期格式。
输出结果为类似于 "2022-01-09" 的日期字符串。
php随机生成一周的天气温度
代码如下:
```php
<?php
// 生成一周的随机温度
$temperatures = array();
for ($i = 0; $i < 7; $i++) {
$temperature = rand(0, 30);
$temperatures[] = $temperature;
}
// 输出一周的温度
echo "一周的温度如下:\n";
echo "周一:" . $temperatures[0] . "℃\n";
echo "周二:" . $temperatures[1] . "℃\n";
echo "周三:" . $temperatures[2] . "℃\n";
echo "周四:" . $temperatures[3] . "℃\n";
echo "周五:" . $temperatures[4] . "℃\n";
echo "周六:" . $temperatures[5] . "℃\n";
echo "周日:" . $temperatures[6] . "℃\n";
?>
```
该代码会生成一个包含七个元素的数组 `$temperatures`,每个元素都是一个随机生成的温度值。然后使用 `echo` 输出每天的温度。