我现在用这个来打印当前的日期,我想用类似的格式来打印十四天前的日期。
let date = (( new Date()).getMonth()+ 1 ) + "-" + ( new Date()).getDate() + "-" + ( new Date()).getFullYear()
console.log(date)
我想用类似的格式来打印14天前的日期。可以用javascript来实现吗?
你可以使用"-"+(new Date(.getDate())+"-"+(new Date(.getFullYear())。瞬间 为此
let calculatedDate = moment().add(-14, 'day').format("M-DD-YYYY")
document.querySelector('h3').innerHTML = calculatedDate
<script src="https://momentjs.com/downloads/moment-with-locales.js"></script>
<h3></h3>