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
: 2186 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

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

//calling function

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.

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

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

Full Name *

Email *

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