Javascript – Date

Date() constructor is used to work with dates and times.
It checks Local Time (The loac time of your timezone) or the Universal Time UTC
For more information about Time Zones and UTC see Wikipedia at: http://en.wikipedia.org/wiki/Coordinated_Universal_Time

To get date – getDate – Statement():

<!DOCTYPE html>
<html>
<body>

<p id="demo">Click the button to display todays day of the month.</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction()
{
var d = new Date();
var x = document.getElementById("demo");
x.innerHTML=d.getDate(); // Return the day of the month
}
</script>

</body>
</html>

To get date – getDate() – List:


// Local Time of your time zone ##############################################################

var d = new Date();
var n = d.getDate();         // Return the day of the month

var d = new Date();
var n = d.getDay();          // Return the day of the week -> Sunday is 0, Monday is 1, and so on.

var d = new Date();
var n = d.getFullYear();     // Return local time year -> 2013

var d = new Date();
var n = d.getHours();        // Return local time hours -> from 0 to 23

var d = new Date();
var n = d.getMilliseconds(); // Return local time milliseconds -> from 0 to 999

var d = new Date();
var n = d.getMinutes();      // Return local time minutes -> from 0 to 59

var d = new Date();
var n = d.getMonth();        // Return local time mounth -> January is 0, February is 1, and so on.

var d = new Date();
var n = d.getSeconds();      // Return local time seconds -> from 0 to 59

var d = new Date();
var n = d.getTime();         // Return milliseconds since 1970/01/01 -> 1384021650070

// UTC Coordinated Universal Time #############################################################

var d = new Date()
var n = d.getTimezoneOffset(); // Return the timezone difference between UTC and Local Time: -> -60

var d = new Date();
var n = d.getUTCDate();        // Return universal time month -> from 1 to 31

var d = new Date();
var n = d.getUTCDay();         // Return universal time day -> Sunday is 0, Monday is 1, and so on.

var d = new Date();
var n = d.getUTCFullYear();    // Return universal time year -> 2013

var d = new Date();
var n = d.getUTCHours();       // Return universal time hours -> from 0 to 23

var d = new Date();
var n = d.getUTCMilliseconds();

var d = new Date();
var n = d.getUTCMinutes();

var d = new Date();
var n = d.getUTCMonth();

var d = new Date();
var n = d.getUTCSeconds();

To set date – setDate():

<!DOCTYPE html>
<html>
<body>

<p id="demo">Click the button to display the date after changing the day of the month.</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction()
{
var d = new Date();
d.setDate(15);
var x = document.getElementById("demo");
x.innerHTML=d;
}
</script>

</body>
</html>

Notice:

d.setDate(15); // set the day of the month -> 15

The result is:

Fri Nov 15 2013 19:48:53 GMT+0100 (ora solare Europa occidentale)

To set date – setDate() – list:


// Local Time of your time zone ##############################################################

var d = new Date();
d.setDate(15);

var d = new Date();
d.setFullYear(2020);

... and so on ... see the official manuals

// UTC Coordinated Universal Time #############################################################

var d = new Date();
d.setUTCDate(15);

var d = new Date();
d.setUTCFullYear(1992);

... and so on ... see the official manuals

To see the complete list: http://www.w3schools.com/jsref/jsref_obj_date.asp

My official WebSite >