Languages
[Edit]
EN

C# / .NET - DateTime.Now precision

9 points
Created by:
Marcin
2471

Using DateTime structure in C# / .NET it is possible make operations with maximal precision 100 ns, so it is impossible to see difference during operating on times that are smaller than 100 ns.

DateTime.Now property precision example

DateTime now = DateTime.Now;

Console.WriteLine($"{now:o}");

Output:

2019-08-20T21:38:06.2885653+01:00

Where:

  • 2019 - year
  • 08 - month (August)
  • 20 - day of month
  • 21 - hour
  • 38 - minute
  • 06 - second
  • 288 - millisecond part (from: ...2885653...)
  • 565 - microsecond part (from: ...2885653...)
  • 300 - nanosecond part (from: ...2885653...)
  • +01:00 - time offset (GMT+1)
Note: as it has been shown it is possible only to get multiple of one hundred of nanoseconds of DateTime

References

  1. DateTime.Now Property - Microsoft Docs
Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.