JavaScript Date getTime() Method

Definition and Usage

getTime() The method returns the number of milliseconds between midnight on January 1, 1970, and the specified date.

Instance

Example 1

Return the milliseconds since 1970/01/01:

var d = new Date();
var n = d.getTime();

Try It Yourself

Example 2

Calculate the number of years 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);

Try It Yourself

Syntax

Date.getTime()

Parameters

No parameters.

Technical Details

Return Value: A number representing the milliseconds since midnight on January 1, 1970.
JavaScript Version: ECMAScript 1

Browser Support

Method Chrome IE Firefox Safari Opera
getTime() Support Support Support Support Support

Related Pages

Tutorial:JavaScript Date

Tutorial:JavaScript Date Format

Tutorial:JavaScript Object Constructor