1

I've been working on an app which is working across 500 iPads and whilst testing across the devices I noticed the times were incorrect across almost all of them, because it was using the time from the device and not the server. I'm new new Date();

Is there a way I can use the server time instead? I'm fairly new to Node, so please forgive me if it's something obvious!

Update:

Yes I'm trying to display the exact server time on the devices, not the time on the local device. I have looked around, but couldn't find any solid answers. Again, apologies if I have been vague, but as I said, I'm fairly new to Node.

Ewan Valentine
  • 3,741
  • 7
  • 43
  • 68

2 Answers2

2

Try using moment

npm install moment --save

Full documentation

http://momentjs.com/docs

Check their documentation about getting local time:

http://momentjs.com/docs/#/manipulating/local/

Roysh
  • 1,542
  • 3
  • 16
  • 26
2

This route(in Node.js) helped for me:

app.get('/', (req, res) => {
    res.send('<script>var r=new Date().valueOf() + ( ' + (new Date().getTimezoneOffset()) +
        ' - (new Date().getTimezoneOffset()) ) * -60000;' +
        'setInterval(()=>{document.body.innerHTML = (new Date(r+=1000)).toLocaleString("en",{weekday:"long", month:"long", day:"numeric", year:"numeric", hour:"numeric", minute:"numeric", second:"numeric", hour12:false})},1000);' +
        '</script>');
});
radhe_shyam
  • 159
  • 1
  • 5