Search code examples
c#node.jsstopwatch

Stopwatch.GetTimestamp() C# equivalent in NodeJS


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


Solution

  • 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.