3 回答

TA贡献1851条经验 获得超5个赞
使用 PHP 获取今天的日期并更改格式
$origDate = "2019-01-15";
$newDate = date("m-d-Y", strtotime($origDate));
echo $newDate;
输出
01-15-2019
用js
var date = new Date();
var year=date.getFullYear();
var month= date.getMonth();
var date=date.getDay();
console.log(` ${day}:${month}:${year}`);

TA贡献1871条经验 获得超8个赞
当您已经拥有获得所需格式的所有内容时,请不要使用服务器端逻辑:
<script>
$(document).ready(function() {
let today = new Date();
let strToday = today.getFullYear() + "-" + today.getMonth() + "-" + today.getDay();
console.log(strToday);
});
</script>

TA贡献1856条经验 获得超5个赞
只需格式化日期。不要忘记 getMonth() 是从零开始的。
const date = new Date();
const mm = date.getMonth() + 1;
const dd = date.getDate();
const format = [
date.getFullYear(),
(mm > 9 ? '' : '0') + mm,
(dd > 9 ? '' : '0') + dd
].join('-');
console.log(format);
- 3 回答
- 0 关注
- 278 浏览
添加回答
举报