Languages
[Edit]
EN

C# / .NET - convert DateTime to DateTimeOffset

1 points
Created by:
JustMike
26120

In C# / .NET it is possible to convert DateTime object DateTimeOffset in the following ways.

1. DateTimeOffset class casting example

DateTimeOffset now = (DateTimeOffset)DateTime.Now;

Console.WriteLine(now.ToString());

Output:

08/14/2019 23:41:58 +01:00
Note: this example has been run with independent culture.

2. DateTimeOffset class constructor example

DateTimeOffset now = new DateTimeOffset(DateTime.Now);

Console.WriteLine(now.ToString());

Output:

08/14/2019 23:47:04 +01:00
Note: this example has been run with independent culture.

References

  1. DateTime Structure Method - Microsoft Docs
  2. Converting between DateTime and DateTimeOffset - Microsoft Docs

C# - DateTime conversion

Native Advertising
50 000 ad impressions - 449$
🚀
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

❤️💻 🙂

Join