How to get current timestamp using javascript?


Hello, How can I get a timestamp in JavaScript? I need simple, understandable & easy code.


Asked by:- jon
1
: 2119 At:- 3/14/2018 7:46:57 PM
javascript timestamp in JavaScript







1 Answers
profileImage Answered by:- jaiprakash

You can create a function in Javascript 1.5 and above using Date.now()

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

//calling function
time();

To get the Unix timestamp you can use the below code

var UnixTimeStamp = Math.round((new Date()).getTime() / 1000);

the above code convert the current date and time to a UNIX timestamp, getTime() returns milliseconds from the UNIX epoch, so divide it by 1000 to get the seconds representation. It is rounded using Math.round() to make it a whole number.

2
At:- 3/15/2018 11:39:27 AM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use