getTime (JavaScript)

Gets the time as a numeric value.

Defined in

Date (Standard - JavaScript)

Syntax

getTime() : long
Return value Description
long The number of milliseconds from 0 hours on January 1, 1970 UTC.

Examples

This example has two scripts and a data binding. The first script is the afterPageLoad event for a page. It sets a global variable to the numeric value of the current time (that is, the time when the page is loaded).
// afterPageLoad sets the global variable baseTime
var date = new Date();
sessionScope.baseTime = date.getTime()
The second script is the onClick event for a button. It subtracts the numeric value of the time when the page was loaded from the current time, then calculates the minutes, seconds, and milliseconds.
// Button whose onClick sets the global variable deltaTime
var date = new Date();
var t = date.getTime() - sessionScope.baseTime;
var ms = t % 1000;
var s = (t - ms) / 1000;
var seconds = s % 60;
var minutes = (s - seconds) / 60;
sessionScope.deltaTime = minutes + " min, " +
	seconds + " sec, " + ms + " ms"
The data binding is for a computed field and has the following value. Whenever the user clicks the button, this field displays the time difference from when the page was loaded.
sessionScope.deltaTime