Below is the example of Date getTime() method.
// Here a date has been assigned
// while creating Date object
'October 15, 1996 05:35:32'
// hour from above is being
// extracted using getTime()
B = A.getTime();
// Printing time in milliseconds.
The date.getTime() method method used to returns the number of milliseconds since 1 January 1970. when a new Date object is created it stores the date and time data when it is created. When the getTime() method is called on this date object it returns the number of milliseconds since 1 January 1970 (Unix Epoch).
Parameters: This method does not accept any parameter.
Return type: A numeric value equal to no of milliseconds since Unix Epoch.
More codes for the above method are as follows:
Program 1: Here the date of the month must lie in between 1 to 31 because no date can have month greater than 31. That is why it returns NaN i.e, Not a Number if the month in the Date object is greater than 31. Hours will not have existed when the date of the month given as 33 i.e, greater than 31.
Program 2: Here we will calculate the user age by providing the birth date of the user.
- Google Chrome
- Internet Explorer