18910140161

JavaScript-日历日期提前一天显示-堆栈溢出

顺晟科技

2022-10-18 14:13:56

73

这是在CodePen上设置的,并且是用JavaScript和HTML编写的。我怎样才能纠正代码,以便只有一个日期时间变量,它显示今天的日历日期?https://codepen.io/artomic/pen/lylxwpb.

        const currentDate = new Date();
        const dateTime = currentDate.getDate() + "/" +
         (currentDate.getMonth() + 1) + "/" +
         currentDate.getFullYear() + " " +
         currentDate.getHours() + ":" +
         currentDate.getMinutes()
        
        
        var months = ['January','February','March','April','May','June','July',
       'August','September','October','November','December'];       
        var tomorrow = new Date();
        tomorrow.setTime(tomorrow.getTime() + (1000*3600*24));       
        document.getElementById("spanDate").innerHTML = months[tomorrow.getMonth()] + " " + 
        tomorrow.getDate()+ ", " + tomorrow.getFullYear();
        
        
        const dateTimeB = new Date().toLocaleTimeString('en-US', {
        hour12: false,
        hour: "numeric",
        minute: "numeric"
        });
        console.log(dateTimeB)
        
        document.getElementById("dateTimeB").innerHTML=dateTimeB
        
        HTML
        
        <span id="spanDate"></span> 
        <br>
        <span id= "dateTimeB"</span>
        
        <span id="dateTime"></span>
         

顺晟科技:

  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航