Saturday, November 17, 2018

JavaScript Date Objects


JavaScript Date Object lets us work with dates:
Sun Nov 18 2018 10:31:15 GMT+0430 (Afghanistan Time)

Example :

var d = new Date();

JavaScript Date Output

By default, JavaScript will use the browser's time zone and display a date as a full text string:
Sun Nov 18 2018 10:31:15 GMT+0430 (Afghanistan Time)
You will learn much more about how to display dates, later in this tutorial.

Creating Date Objects

Date objects are created with the new Date() constructor.
There are 4 ways to create a new date object:

new Date()
new Date(year, month, day, hours, minutes, seconds, milliseconds)
new Date(milliseconds)
new Date(date string)

new Date()

new Date() creates a new date object with the current date and time:

var d = new Date();

Date objects are static. The computer time is ticking, but date objects are not.

new Date(year, month, ...)

new Date(year, month, ...) creates a new date object with a specified date and time.
7 numbers specify year, month, day, hour, minute, second, and millisecond (in that order):

var d = new Date(201811241033300);

new Date(dateString)

new Date(dateString) creates a new date object from a date string:

var d = new Date("October 13, 2014 11:13:00");



























Share:

0 comments:

Post a Comment

Contact Form

Name

Email *

Message *

Popular Posts

Blog Archive

Blog Archive

Hassan.mosmer1@gmail.com