0

I am searching for a function that will return nearly same output for my all visitors which they are locating different countries

var d1 = new Date(); var d2 = new Date( d1.getUTCFullYear(), d1.getUTCMonth(), d1.getUTCDate(), d1.getUTCHours(), d1.getUTCMinutes(), d1.getUTCSeconds() ); Math.floor(d2.getTime()/ 1000); 

I found this from stackoverflow but i see it doesn't work, it doesn't give same output with my vps which is located in france and totally different result from http://www.unixtimestamp.com/

var options = { timeZone: 'UTC', year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric' }, formatter = new Intl.DateTimeFormat([], options) formatter.format(new Date()) 

this returns me right result but it's not timestamp. Any help appreciated.

0

2 Answers 2

1

You need Date.UTC:

var d1 = new Date(); var d2 = Date.UTC(d1.getUTCFullYear(), d1.getUTCMonth(), d1.getUTCDate(), d1.getUTCHours(), d1.getUTCMinutes(), d1.getUTCSeconds()); var timestamp = Math.floor(d2 / 1000); document.write(timestamp);

Sign up to request clarification or add additional context in comments.

2 Comments

well i tried parseInt(new Date().getTime()/1000); it already returns as utc
So the question is solved then? You should post an answer.
0

sorry it's my mistake javascript already uses utc as default ,

you can just use this code snipet to get utc timestamp

parseInt(new Date().getTime()/1000); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.