Languages
[Edit]
EN

C# / .NET - create date and time from milliseconds

12 points
Created by:
Theodora-Battle
528

In C# / .NET it is possible to get DateTime instance from total milliseconds in few ways.

1. DateTime from total milliseconds example

Edit

Example:

Output:

Note: time is measured since 01-01-0001 00:00:00.000.

2. DateTime from Unix total milliseconds custom example

Edit

Example:

Output:

Note: Unix time is measured from 01-01-1970 UTC date.

3. DateTimeOffset.FromUnixTimeMilliseconds method example

Edit

Output:

Node: this approach is available since .NET 4.6.

References

Edit
  1. DateTime Struct - Microsoft Docs
  2. DateTimeOffset.ToUnixTimeMilliseconds Method - Microsoft Docs
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join