Javascript 如何在<;h>;元素?

Javascript 如何在<;h>;元素?,javascript,html,datetime,Javascript,Html,Datetime,我想在网页标题中显示当前系统日期减去7天 <h1>Is this article older than (7 days prior today's date)</h1> 此文章是否早于(今天日期前7天) 我将如何实现在元素中显示此内容 谢谢。使用javascriptDate对象。请注意,月份索引是基于0的 var d=新日期(); d、 setDate(d.getDate()-7); document.getElementById('heading').inner

我想在网页标题中显示当前系统日期减去7天

 <h1>Is this article older than (7 days prior today's date)</h1>
此文章是否早于(今天日期前7天)
我将如何实现在元素中显示此内容


谢谢。

使用javascript
Date
对象。请注意,月份索引是基于0的

var d=新日期();
d、 setDate(d.getDate()-7);
document.getElementById('heading').innerHTML=“这篇文章是否早于”+(d.getMonth()+1)+“/”+d.getDate()+“/”+d.getFullYear()”