0

I have a Node.js app. That app uses the present package. This package provides high resolution timestamps. These timestamps are represented as doubles. I need to figure out how to get a high resolution timestamp in C#.

How do I get a high resolution timestamp (up to microsecond precision) in C#?

Thank you!

xam developer
  • 1,923
  • 5
  • 27
  • 39

1 Answers1

1

Stopwatch class provides access to time with the highest resolution available. You will need to combine calls to Elapsed with single call to DateTime.UtcNow if you need timestamps similar to JavaScript Date.now.

If you are fine with just DateTime resolution - check out Function that creates a timestamp in c# - covers many options, including using DateTime and integer counter to provide timestamps that are sortable and guaranteed to be unique in the single process.

Note: as with most timestamps you can't relay on timestamps created on different machines/process for ordering entries/logs, so picking higher resolution timestamps over simply unique once may not give much benefits.

Community
  • 1
  • 1
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179