JavaScript getTime()Method
Examples
Returns the number of milliseconds since January 1, 1970:
var d = new Date();
var n = d.getTime();
var n = d.getTime();
nOutput:
Try it Yourself »
Definition and Usage
The getTime() method returns the number of milliseconds since January 1, 1970.
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the getTime() method
Syntax
Date.getTime()
Return Value
| Type | Description |
|---|---|
| Number | The number of milliseconds between the specified date and time and midnight January 1, 1970 (GMT time). |
Technical Details
| JavaScript Version: | 1.0 |
|---|
More Examples
Examples
In the following example, we will calculate how many years have passed from 1970/01/01 to now:
var minutes=1000*60;
var hours=minutes*60;
var days=hours*24;
var years=days*365;
var d=new Date();
var t=d.getTime();
var y=Math.round(t/years);
var hours=minutes*60;
var days=hours*24;
var years=days*365;
var d=new Date();
var t=d.getTime();
var y=Math.round(t/years);
yOutput:
Try it Yourself »
Other Extensions
JavaScript Date Object