下边 Z-BlogPHP 应用里用到了「获取时间戳所在周的第一天」的功能,然而一开始的实现并不对「- -」;
碎雨集 - Z-Blog 应用中心:
https://app.zblogcn.com/?id=21047
一开始是想直接拿到00:00:00
的时间戳,果然太麻烦了就容易出错;
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| function mz_ShikonNoTama_GetCurMonday($time) {
$week = date("N", $time); return $time - ($week - 1) * 86400;
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| $arr = [1642896000, 1642953599, 1642953600, 1642957612]; $rltHTML = ''; for ($i = 0; $i < count($arr); $i++) { $time = $arr[$i]; $date = date("Y-m-d H:i", $time); $week = date("N", $time); $monday = $time - ($week - 1) * 86400; $rltHTML .= strtr($tpl, [ '{key}' => 'time', '{value}' => $date, ]); $rltHTML .= strtr($tpl, [ '{key}' => 'week', '{value}' => $week, ]); $rltHTML .= strtr($tpl, [ '{key}' => 'monday', '{value}' => date("Y-m-d H:i", $monday), ]); $rltHTML .= "<br>"; }
echo $rltHTML;
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| time:2022-01-23 08:00
week:7
monday:2022-01-17 08:00
time:2022-01-23 23:59
week:7
monday:2022-01-17 23:59
time:2022-01-24 00:00
week:1
monday:2022-01-24 00:00
time:2022-01-24 01:06
week:1
monday:2022-01-24 01:06
|