JavaScript getTime()Method

Date 对象参考手册JavaScript Date Object

Examples

Returns the number of milliseconds since January 1, 1970:

var d = new Date();
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

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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);

yOutput:


Try it Yourself »


Date 对象参考手册JavaScript Date Object

Other Extensions