Skip to main content

How to Turn a DateTimeOffset into a UTC DateTime with UtcDateTime in C#

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

offset.UtcDateTime gives you the moment a DateTimeOffset stands for as a DateTime in UTC, with its Kind set to Utc. Use it when the code you call takes a DateTime, not a DateTimeOffset.

Microsoft's reference for DateTimeOffset.UtcDateTime: Gets a DateTime value that represents the Coordinated Universal Time (UTC) date and time of the current DateTimeOffset object. A DateTimeOffset holds a date and time together with its offset from UTC, such as +01:00. A DateTime has no offset. Instead, its Kind says whether it's in UTC, in local time, or neither. UtcDateTime does two things, in the reference's words: It converts the date and time of the current DateTimeOffset object to Coordinated Universal Time (UTC). and It converts the DateTimeOffset value to a DateTime value.

Syntax​

Syntax
DateTime <utc> = <offset>.UtcDateTime;
PartWhat it is
<offset>A DateTimeOffset: a date and time with its offset from UTC
.UtcDateTimeA read-only property: the same moment in UTC, as a DateTime
DateTime <utc>The result. Its Kind is Utc

The Example​

A console app called UtcDateTimeProperty creates two moments, each written with its own offset: a meeting at 14:45 on 3 December 2026 at +01:00, and a call at 22:10 on 2 December at -07:00. It turns both into UTC with UtcDateTime, and prints each one before and after, with the Kind of the result. The values are fixed, so the output is the same on every computer.

Prerequisites​

  • The .NET 10 SDK. dotnet --version prints a version that starts with 10.0.

Step 1: Create a Console App​

Terminal
dotnet new console -n UtcDateTimeProperty
cd UtcDateTimeProperty
Output
The template "Console App" was created successfully.

Processing post-creation actions...
Restoring /Users/you/source/UtcDateTimeProperty/UtcDateTimeProperty.csproj:
Determining projects to restore...
Restored /Users/you/source/UtcDateTimeProperty/UtcDateTimeProperty.csproj (in 42 ms).
Restore succeeded.

dotnet new console -n UtcDateTimeProperty creates a folder named UtcDateTimeProperty with a project file and a Program.cs, and cd moves into it. Everything this example uses is part of .NET, so there's no package to add. Open the folder in VS Code, or UtcDateTimeProperty.csproj in Visual Studio.

Step 2: Write the Code​

Replace everything in Program.cs. First the two moments:

Program.cs (two moments)
// Two moments, each written with its own offset from UTC.
DateTimeOffset meeting = new(2026, 12, 3, 14, 45, 0, TimeSpan.FromHours(1));
DateTimeOffset call = new(2026, 12, 2, 22, 10, 0, TimeSpan.FromHours(-7));

The first six numbers are the year, month, day, hour, minute and second. The last argument is the offset: TimeSpan.FromHours(1) is one hour ahead of UTC, and TimeSpan.FromHours(-7) seven hours behind.

Then turn them into UTC:

Program.cs (UtcDateTime)
// UtcDateTime gives the same moment as a DateTime in UTC.
DateTime meetingUtc = meeting.UtcDateTime;
DateTime callUtc = call.UtcDateTime;

meeting.UtcDateTime returns a DateTime that holds the same moment in UTC, and so does call.UtcDateTime.

Last, print them:

Program.cs (print them)
CultureInfo invariant = CultureInfo.InvariantCulture;
Console.WriteLine($"Meeting: {meeting.ToString("O", invariant)}");
Console.WriteLine($"UtcDateTime: {meetingUtc.ToString("O", invariant)}, Kind {meetingUtc.Kind}");
Console.WriteLine($"Call: {call.ToString("O", invariant)}");
Console.WriteLine($"UtcDateTime: {callUtc.ToString("O", invariant)}, Kind {callUtc.Kind}");

ToString("O", invariant) prints the full date and time in a fixed format: a DateTimeOffset ends with its offset, and a UTC DateTime ends with Z. Kind shows which kind of DateTime each result is. CultureInfo comes from the System.Globalization namespace, hence the using line at the top.

Step 3: Run It​

Run it in VS Code's terminal, or press Ctrl+F5 in Visual Studio:

Terminal
dotnet run
Output
Meeting: 2026-12-03T14:45:00.0000000+01:00
UtcDateTime: 2026-12-03T13:45:00.0000000Z, Kind Utc
Call: 2026-12-02T22:10:00.0000000-07:00
UtcDateTime: 2026-12-03T05:10:00.0000000Z, Kind Utc

macOS-style terminal window titled Terminal — UtcDateTimeProperty showing dotnet run printing the meeting at 14:45 plus 01:00 with a UtcDateTime of 13:45Z and Kind Utc, and the call at 22:10 minus 07:00 on 2 December with a UtcDateTime of 05:10Z on 3 December and Kind Utc

The meeting at 14:45 at +01:00 became 13:45 in UTC, one hour earlier. The call at 22:10 on 2 December at -07:00 became 05:10 on 3 December: seven hours later, on the next day. Both results end with Z and have Kind Utc. The reference explains the arithmetic: The conversion is performed by subtracting the value of the Offset property from the date and time of the current DateTimeOffset object. Subtracting an offset of -7 hours adds 7 hours.

The Complete File​

macOS-style code window titled Program.cs — UtcDateTimeProperty showing a meeting at plus one hour and a call at minus seven hours created as DateTimeOffset values, their UtcDateTime properties read into DateTime variables, and each value printed with the O format and the Kind of the result

Program.cs
using System.Globalization;

// Two moments, each written with its own offset from UTC.
DateTimeOffset meeting = new(2026, 12, 3, 14, 45, 0, TimeSpan.FromHours(1));
DateTimeOffset call = new(2026, 12, 2, 22, 10, 0, TimeSpan.FromHours(-7));

// UtcDateTime gives the same moment as a DateTime in UTC.
DateTime meetingUtc = meeting.UtcDateTime;
DateTime callUtc = call.UtcDateTime;

CultureInfo invariant = CultureInfo.InvariantCulture;
Console.WriteLine($"Meeting: {meeting.ToString("O", invariant)}");
Console.WriteLine($"UtcDateTime: {meetingUtc.ToString("O", invariant)}, Kind {meetingUtc.Kind}");
Console.WriteLine($"Call: {call.ToString("O", invariant)}");
Console.WriteLine($"UtcDateTime: {callUtc.ToString("O", invariant)}, Kind {callUtc.Kind}");

Common Mistakes​

MistakeWhat happensDo this instead
Assigning a DateTimeOffset to a DateTimeDateTime when = meeting; didn't build: error CS0029: Cannot implicitly convert type 'System.DateTimeOffset' to 'System.DateTime'Read the property: DateTime when = meeting.UtcDateTime;
Reading .DateTime to get UTCmeeting.DateTime kept the clock time, 14:45, with Kind Unspecified. The offset was dropped, not appliedUse UtcDateTime, which gave 13:45 with Kind Utc
Reading .ToUniversalTime().DateTimeIt gave the right time, 13:45, but with Kind Unspecified. The reference: Retrieving the value of the UtcDateTime property is equivalent to calling the current DateTimeOffset object's ToUniversalTime.DateTime property, except that the Kind property of the latter DateTime value is DateTimeKind.Unspecified.Use UtcDateTime, which gives the same time with Kind Utc

FAQ​

How do I turn the UTC DateTime back into a DateTimeOffset?​

Pass it to the DateTimeOffset constructor:

Program.cs (back to a DateTimeOffset)
using System.Globalization;

DateTimeOffset meeting = new(2026, 12, 3, 14, 45, 0, TimeSpan.FromHours(1));
DateTime meetingUtc = meeting.UtcDateTime;

// Turn the UTC DateTime back into a DateTimeOffset.
DateTimeOffset back = new(meetingUtc);
Console.WriteLine($"Back again: {back.ToString("O", CultureInfo.InvariantCulture)}");
Console.WriteLine($"Same moment: {back == meeting}");
Output
Back again: 2026-12-03T13:45:00.0000000+00:00
Same moment: True

Because its Kind is Utc, the new value got an offset of +00:00. The constructor's reference: If the value of DateTime.Kind is DateTimeKind.Utc, the DateTime property of the new instance is set equal to dateTime, and the Offset property is set equal to Zero. It's written differently from the original 14:45 at +01:00, but == printed True: it's the same moment.

Does it work on the current time?​

Yes. DateTimeOffset.UtcNow.UtcDateTime gives the current moment as a UTC DateTime. This program prints only its Kind, not the time:

Program.cs (the current time)
DateTime now = DateTimeOffset.UtcNow.UtcDateTime;
Console.WriteLine($"Kind: {now.Kind}");
Output
Kind: Utc

Conclusion​

UtcDateTime turns a DateTimeOffset into a DateTime in UTC: it subtracts the offset and sets Kind to Utc. Use it rather than .DateTime, which drops the offset, or .ToUniversalTime().DateTime, which loses the Kind. To go back, pass the UTC DateTime to the DateTimeOffset constructor.

Additional Resources​