Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript getTime() Method

JavaScript getTime() Method

Date Object Reference JavaScript Date object

Example

Return the number of milliseconds since January 1, 1970:

var d = new Date();

var n = d.getTime();

n Output result:

Try it »


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 (GMT) on January 1, 1970.

Technical Details

JavaScript version: 1.0

More examples

Example

In the example below, we will calculate how many years have passed since 1970/01/01:

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

y Output result:

Try it »


Date Object Reference JavaScript Date object