3 回答
TA贡献1842条经验 获得超21个赞
这是 PHP 中的:
$result=array();
for($months=5;$months>=0;$months--){
if(!$months){
$month_name = date("F");
}else{
$month_name = date("F", strtotime("-$months month"));
}
$result[]='<button>'.$month_name.'</button>';
}
echo implode('<br>', $result);
TA贡献1878条经验 获得超4个赞
你可以在 php 中这样做:
<?php
echo "<button> " . date('F') . "</button>";
for ($i = 1; $i < 6; $i++) {
echo "<button> " . date('F', strtotime("-$i month")) . "</button>";
}
?>
TA贡献1804条经验 获得超8个赞
我用 JavaScript 解决了
const monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];
const maxDateCnt = 11;
const countFiveMonts = [];
const dateTime = new Date();
let monthCnt = dateTime.getMonth();
let monthCpy = monthCnt;
for(let i = 0; i < 6; i++){
let current;
if(monthCnt > maxDateCnt){
monthCnt -= 12;
monthCpy = monthCnt;
current = monthNames[monthCnt];
}else{
current = monthNames[monthCpy + i];
}
countFiveMonts.push(current);
monthCnt++;
}
console.log(countFiveMonts);
- 3 回答
- 0 关注
- 93 浏览
添加回答
举报