...
Code Block |
---|
var d = new Date(); document.getElementById("demo").innerHTML += d.getFullYear(); // Get the year as a four digit number (yyyy) document.getElementById("demo").innerHTML += d.getMonth(); // Get the month as a number (0-11) document.getElementById("demo").innerHTML += d.getDate(); // Get the day as a number (1-31) document.getElementById("demo").innerHTML += d.getHours(); // Get the hour (0-23) document.getElementById("demo").innerHTML += d.getMinutes(); // Get the minute (0-59) document.getElementById("demo").innerHTML += d.getSeconds(); // Get the second (0-59) document.getElementById("demo").innerHTML += d.getMilliseconds(); // Get the millisecond (0-999) document.getElementById("demo").innerHTML += d.getTime(); // Get the time (milliseconds since January 1, 1970) document.getElementById("demo").innerHTML += d.getDay(); // Get the weekday as a number (0-6) document.getElementById("demo").innerHTML += Date.now(); // Get the time. ECMAScript 5. |
If you want to convert it to string in Javascript
Code Block |
---|
var d = new Date();
alert( d.toString()); |