X
HOME HTML5 CSS3 JAVASCRIPT SQL PHP5 JQUERY ANGULAR BOOTSTRAP3 XML MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

JavaScript getTime() Method

Date Object Reference JavaScript Date Object

Example

Return the number of milliseconds since 1970/01/01:

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

The result of n could be:


Try it yourself »

More "Try it Yourself" examples below.


Definition and Usage

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


Browser Support

Method
getTime() Yes Yes Yes Yes Yes


Syntax

Date.getTime()

Parameters

None

Technical Details

Return Value: A Number, representing the number of milliseconds since midnight January 1, 1970
JavaScript Version: 1.0


Examples

More Examples

Example

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

The result of y will be:


Try it yourself »


Date Object Reference JavaScript Date Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook