0

I want to get the exact date and time when user opens a page in his browser. I am trying to achieve this by using 'new Date()'.

 console.log(new Date());

Now, the issue is that it is picking user's machine time by default. For example, if I change my machine time manually, the output will be changed accordingly.

  • Maybe a time service can help, e.g. [https://timeapi.io/](https://timeapi.io/) – KooiInc Jun 23 '22 at 06:04
  • Most computer date systems (including ECMAScript/javascript) use UTC for the base time system. Regional settings for timezone and DST are used for date display and calculations. The settings may or may not match the user's actual location. – RobG Jun 24 '22 at 09:17

1 Answers1

0

There are several ways to achieve this, 2 are listed below:

  1. Use a timeserver, for instance via ntp-time package

https://www.npmjs.com/package/ntp-time

  1. Use a server request (requires that you host your Angular SPA on a server):

Right way to get Web Server time and display it on Web Pages

Charlie V
  • 980
  • 1
  • 6
  • 12