0

I'm trying to get Stopwatch.GetTimestamp() equivalent in NodeJS, but I only managed this:

Javascript:

(Date.now()*10000)+621355968000000000; //returns 637414085816080000

C#

Stopwatch.GetTimestamp() // returns 6618676876650

Note that the results are different

Amirhossein Mehrvarzi
  • 18,024
  • 7
  • 45
  • 70
Kronox
  • 13
  • 1
  • 2
  • 1
    Trying to get the same absolute value is not sensible, it is not based on the date. A hard reboot of the machine tends to reset the counter back to 0. [Look here](https://stackoverflow.com/questions/11725691/how-to-get-a-microtime-in-node-js). – Hans Passant Nov 19 '20 at 19:13

2 Answers2

0

Stopwatch.GetTimestamp() gives back results specific to the machine where you run it. Comparing it to Javascript-style timestamps won't work.

O. Jones
  • 103,626
  • 17
  • 118
  • 172
0

Before discussing, You should be aware that :

  • Stopwatch.GetTimestamp() has the ticks since the computer booted if the Stopwatch class uses the system timer. @jonskeet, Microsoft docs
  • Date.now() returns the number of milliseconds since 1970/01/01. W3schools

Now, If you want the same values for both, You should share a similar base time and then count the ticks.

Amirhossein Mehrvarzi
  • 18,024
  • 7
  • 45
  • 70