01-04 Date Object

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Basics Of JavaScript Programming

 Date Object

DATE OBJECT
Date Object is used to work with date and times.
It provides various methods to get, set and manipulate date and times.
These methods are helps you performs some task related to date,
Following example shows the various ways to create date object.

Methods Of Date Object


Sr.No. Method Name Details
1 getFullYear() Returns The Year
2 getMonth() Return the month (0-11) where 0 is January
3 getDate() Returns the day of the month.(1-31)
4 getDay() Returns the day of week (0-6) where 0 is Sunday.
Subject: Java Script Notes Print Date: [16/Oct/24], Page 1 of 5
5 getHours() Returns the hour (0-23)
6 getMinutes() Returns the minutes (0-59)
7 getSeconds() Returns the seconds (0-59)
8 getMilliseconds() Returns the Milli-seconds (0-999)
9 getTime() Returns the no of milliseconds since Jan 1,1970
10 getTimezoneOffset() Returns the difference in minutes between UTC and
Local time.
11 setFullYear(year,month,day) set the full Year. (Month and day are optional)
12 setMonth( month ) Sets the month (0-11) where 0 is January
13 setDate( day ) Sets the day of the month.(1-31)
14 setDay( day ) Sets the day of week (0-6) where 0 is Sunday.
15 setHours( hours ) Sets the hour (0-23)
16 setMinutes( minutes ) Sets the minutes (0-59)
17 setSeconds( seconds ) Sets the seconds (0-59)
18 setMilliseconds( milliseconds) Sets the Milli-seconds (0-999)
19 setTime( milliseconds ) Sets the no of milliseconds since Jan 1,1970

Subject: Java Script Notes Print Date: [16/Oct/24], Page 2 of 5


Formatting Date Functions.
20 toString() Returns a string representation of date
21 toDateString() Return Date part of String
22 toTimeString() Returns Time part of string
23 toUTCString() Convert date to a string in UTC format.
24 toISOString() Returns the date as on ISO 8601 string.
25 toLocaleDateString() Returns the date formatted according to the users
local settings.
26 toLocaleTimeString() Returns the time formatted according to the users
Local settings.
27 toLocaleString() Returns the date and time formatted according to
users local settings.

Subject: Java Script Notes Print Date: [16/Oct/24], Page 3 of 5


Static Methods of Date.
28 Date.now() Returns the current timestamp
(milliseconds since January 1, 1970)
29 Date.parse() Parses the date string and returns the number of
Milliseconds since January 1, 1970.
30 Date.UTC() Returns the number of milliseconds between a
specified date and January 1, 1970 (UTC)

Subject: Java Script Notes Print Date: [16/Oct/24], Page 4 of 5


Subject: Java Script Notes Print Date: [16/Oct/24], Page 5 of 5

You might also like