WebMasterCampus
WEB DEVELOPER Resources

Javascript How to Get a Timestamp

Learn How to Get a Timestamp in Javascript


Javascript Get a Timestamp

A timestamp is a single number that represents the current time and date.

JS TimeStamp Example

	Date.now()

OR

	+new Date

JS TimeStamp in Seconds

	Math.floor(Date.now() / 1000)

Date.now() is better because it’s shorter & doesn’t create a new Date object.

Date.now() is not supported on IE 8 because it was available from JavaScript 1.5.

	var time = Date.now || function() {
	  return +new Date;
	};

	time();

Read more about Date.now()

Created with love and passion.