
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Date.getTime() function JavaScript
The Date object is a data type built into the JavaScript language. Date objects are created with the new Date( ) as shown below.
Once a Date object is created, a number of methods allow you to operate on it. Most methods simply allow you to get and set the year, month, day, hour, minute, second, and millisecond fields of the object, using either local time or UTC (universal, or GMT) time.
JavaScript date getTime() method returns the numeric value corresponding to the time for the specified date according to universal time. The value returned by the getTime method is the number of milliseconds since 1 January 1970 00:00:00.
Syntax
Its syntax is as follows
dateObj.getTime();
Example
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> var dateObj = new Date('september 26, 89 12:4:25:96'); document.write("Time value: "+dateObj.getTime()); </script> </body> </html>
Output
Time value: 622794865096
Example
In the same way if you haven’t passed anything while creating the date object this function returns the Current hour of the day.
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> var dateObj = new Date(); document.write("Time value: "+dateObj.getTime()); </script> </body> </html>
Output
Time value: 1539764866888
- Related Questions & Answers
- Math.atan() function JavaScript
- Math.min() function JavaScript
- JavaScript Sleep() function?
- JavaScript array.includes() function
- JavaScript Array.of() function
- JavaScript Array.prototype.map() function
- JavaScript toLocaleString() function
- JavaScript array.toLocaleString() function
- JavaScript Symbol.for() function
- JavaScript Function Apply
- JavaScript Function Call
- JavaScript Function Definitions
- JavaScript Function Invocation
- JavaScript Function Parameters
- JavaScript Symbol.keyFor() function