How to Catch Unix Timestamp with Javascript?

Asked

Viewed 2,099 times

9

I tried it here in some ways, but it seems to be wrong. An example of what I do:

var data = new Date();
var timestamp = data.getTime() / 1000;

That way is right?

  • A tip. It can change if the device is at the wrong time. And each place has its time. Here it can be 7:22 there is already 8:22. I advise you to do a Timestamp with a language that the aeu server accepts. So everything is fixed and bug-free

  • My question was about how I could get Unix Timestamp and from what I saw in this old question on the same subject, he did not specify which Timestamp he was looking to get. That answer would not be satisfactory in my case, because in my case I would have to divide by 1000. Javascript as I realized works with milliseconds and in my case I would need to convert to seconds to be able to access an API, this difference left me confused so I asked here.

1 answer

9


Right. All we had to do was round up.

Timestamp in milliseconds:

+new Date() //que é o mesmo que new Date().getTime()

Timestamp in seconds:

Math.floor(+new Date() / 1000) //que o mesmo que Math.floor(new Date().getTime()/1000)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.