我有一个简单的文档,其mwe在下面的代码中给出。在左侧和右侧表格单元格中,我希望有“ 0800 hrs LT 8月27日”,在中间表格单元格中,我希望有“ 1800 hrs LTs Aug 26.”。例如。日期将每天变化。我看过的所有帖子对我都没有帮助。我将不胜感激。Zilore Mumba
<!DOCTYPE html>
<html>
<head>
</style>
<script language="JavaScript">
<!-- debut
var day="";
var month="";
var myweekday="";
var year="";
mydate = new Date();
myday = mydate.getDay();
mymonth = mydate.getMonth();
myweekday= mydate.getDate();
weekday= myweekday;
myyear= mydate.getYear();
if (myyear < 1900)
myyear = 1900 + myyear ;
year = myyear ;
if(myday == 0)
....
....
// End -->
</script>
</head>
<body>
<center><table class="a" id="table1" border ="2" cellpadding="10" cellspacing="0">
<tr>
<th><h3>Minimum Temperatures:<br>0800 hrs LT</h3></th>
<th><h3>Maximum Temperatures:<br>1800 hrs LT (D-1)</h3></th>
<th><h3>Rainfall (mm):<br>0800 hrs LT</h3></th>
</tr>
<tr>
<td class="td_size" align="center"> <a target="_self" href="Obs_Output/TminR.png"><img
src="Obs_Output/TminR.png"></a></td>
<td class="td_size" align="center"> <a target="_self" href="Obs_Output/TmaxR.png"><img
src="Obs_Output/TmaxR.png"></a></td>
<td class="td_size" align="center"> <a target="_self" href="Obs_Output/RainfallR.png"><img
src="Obs_Output/RainfallR.png"></a></td>
</tr>
</table></center>
</body>
</html>
巧,moment
您可以使用以下格式设置今天的日期(moment()
)和昨天的日期(moment().subtract(1, "days")
)format('D MMM')
:
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<center><table class="a" id="table1" border ="2" cellpadding="10" cellspacing="0">
<tr>
<th><h3>Minimum Temperatures:<br>0800 hrs LT <div id="today"></div></h3></th>
<th><h3>Maximum Temperatures:<br>1800 hrs LT <div id="yesterday"></div></h3></th>
<th><h3>Rainfall (mm):<br>0800 hrs LT <div id="today"></div></h3></th>
</tr>
<tr>
<td class="td_size" align="center"> <a target="_self" href="Obs_Output/TminR.png"><img
src="Obs_Output/TminR.png"></a></td>
<td class="td_size" align="center"> <a target="_self" href="Obs_Output/TmaxR.png"><img
src="Obs_Output/TmaxR.png"></a></td>
<td class="td_size" align="center"> <a target="_self" href="Obs_Output/RainfallR.png"><img
src="Obs_Output/RainfallR.png"></a></td>
</tr>
</table></center>
</body>
</html>
<script>
(function() {
document.querySelectorAll("#today").forEach(el => {
el.innerHTML = moment().format('D MMM');
});
document.getElementById("yesterday").innerHTML = moment().subtract(1, "days").format('D MMM');
})();
</script>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句