当前位置: 动力学知识库 > 问答 > 编程问答 >

html - jquery shows wrong date

问题描述:

This question already has an answer here:

  • How do I get the current date in JavaScript?

    33 answers

  • Date.getDay() javascript returns wrong day

    6 answers

网友答案:

You should check the manual:

getDay - method returns the day of the week for the specified date according to local time, where 0 represents Sunday
getMonth - An integer number, between 0 and 11, representing the month in the given date according to local time. 0 corresponds to January, 1 to February, and so on.
getYear - A number representing the year of the given date, according to local time, minus 1900

What you are actually looking for is:

<p id="date"></p>
<script>
    var today = new Date();
    var day = today.getDate();
    var month = today.getMonth() + 1;
    var year = today.getFullYear();
    document.getElementById('date').innerHTML = day + "." + month + "." + year;

</script>

</html>
分享给朋友:
您可能感兴趣的文章:
随机阅读: