-2

I want to show the current date in my invoice. To do this, im using the following method:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

Datum:
<p id="date"></p>

<script>
    var today = new Date();
    var day = today.getDay();
    var month = today.getMonth();
    var year = today.getYear();
    document.getElementById('date').innerHTML = day + "." + month + "." + year;

</script>
Liam
  • 27,717
  • 28
  • 128
  • 190
Simagdo
  • 87
  • 1
  • 8

1 Answers1

1

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>

And it has nothing to do wth jQuery :) it's pure javascript.

Dekel
  • 60,707
  • 10
  • 101
  • 129