Date Methods or Functions

How to get today's date, system time and display it using javascript?
or
Using javascript date methods or functions

Explanation

Date is a predefined object in javascript. This object contains methods that can be used to get or set the system date, time, month, day, hours, minutes, seconds, etc.... Contains methods to get and set properties of UTC universal coordinated time. Universal Coordinated Time, UTC is the world time standard also called as Greenwich Mean Time.
A new object has to be created before using its methods.
Creation of new date object:
Example Code: var exd = new Date();
Calling "new Date()" will create a new date object. This object can be used to execute its methods or functions. We have to capture the object in a variable. In the example the object it stored in a variable name exd.
The below table uses the object exd as an example.
MethodExample CodeResultDescription
getDate() exd = new Date();
exd.getDate();
getDate() method returns today's date of the month as in your computer. The range is from 1 to 31.
getUTCDate() exd = new Date();
exd.getUTCDate();
getUTCDate() method return the date value of Universal Coordinated Time. UTC is the world time standard also called as Greenwich Mean Time.
getMonth() exd = new Date();
exd.getMonth();
getMonth() method returns the Month of this year, as in your computer. The result can range from 0 to 11. 0 for january to 11 for december.
getUTCMonth() exd = new Date();
exd.getUTCMonth();
getUTCMonth() returns the UTC month of the year, as in your computer.
getDay() exd = new Date();
exd.getDay();
getDay() method returns the day of the week, as in your computer. The result can range from 0 to 6. 0 for Sunday, 1 for Monday, up to 6 for Saturday.
getUTCDay() exd = new Date();
exd.getUTCDay();
getUTCDay() returns the UTC day of the week, as in your computer.
getHours() exd = new Date();
exd.getHours();
getHours() method returns the current hour of the day, as in your computer. The result can range is from 0 to 24.
getUTCHours() exd = new Date();
exd.getUTCHours();
getUTCHours() returns the UTC hours of the day, as in your computer. [Indian Standard Time is 5.30 hours ahead of UTC].
getMinutes() exd = new Date();
exd.getMinutes();
getMinutes() method returns the minutes of this hour, as in your computer. The result can range is from 0 to 59.
getUTCMinutes() exd = new Date();
exd. getUTCMinutes();
getUTCMinutes() returns the UTC minutes of the hour, as in your computer.
getSeconds() exd = new Date();
exd.getSeconds();
getSeconds() method returns the Seconds of this minute, as in your computer. The result can range is from 0 to 59.
getUTCSeconds() exd = new Date();
exd. getUTCSeconds();
getUTCSeconds() returns the UTC seconds of the minute, as in your computer.
getMilliseconds() exd = new Date();
exd.getMilliseconds();
getMilliseconds() method returns the milli seconds of current second, as in your computer.
getTime() exd = new Date();
exd.getTime();
- Result:
getTime() method returns the current time since 1/1/1970 in milli seconds, as in your computer.
getYear() exd = new Date();
exd.getYear();
getYear() method returns the year since 1900, as in your computer.
getFullYear() exd = new Date();
exd.getFullYear();
getFullYear() method returns the full year, as in your computer.
toGMTString() exd = new Date();
exd.toGMTString();
toGMTString() method returns the date and time in Internet Greenwich Mean Time Format (GMT).

JavaScript dates are stored as the number of milliseconds since midnight of January 1, 1970. This date is called Opoch date.

Ask Questions

Ask Question