In C#, DateTime.ToUniversalTime() converts a local value to Coordinated Universal Time (UTC). The result has Kind.Utc.
If the value is already Utc, it comes back unchanged. If it is Unspecified, .NET assumes it is local time and converts it. Store and send times in UTC to avoid confusion between servers and users.
This is an instance member of System.DateTime. You call it on a DateTime value, such as dt.ToUniversalTime(...). DateTime is a struct, so every value is copied and never changed in place.
Syntax
Call it on a DateTime. It takes no arguments.
C#
DateTime local = new DateTime(2026, 11, 18, 10, 0, 0, DateTimeKind.Local);
DateTime utc = local.ToUniversalTime(); // Kind is Utc
Call
What it does
local.ToUniversalTime()
Local to UTC. Kind becomes Utc.
utc.ToUniversalTime()
A Utc value is returned unchanged.
unspecified.ToUniversalTime()
An Unspecified value is treated as local time.
The change depends on the computer's time zone, so the examples check Kind and offset rules. For a specific zone use TimeZoneInfo.ConvertTimeToUtc(dt, zone).
Library declarations
C#
public DateTime ToUniversalTime();
Parameters
Parameter
Description
None
ToUniversalTime() takes no parameters.
Return Value
Return Value
Description
DateTime
A new DateTime in UTC with Kind.Utc.
C# Examples
Example 1 — Local to Utc
Convert a Local value and read the Kind of the result.
C#
using System;
class Program {
static void Main() {
DateTime local = new DateTime(2026, 11, 18, 10, 0, 0, DateTimeKind.Local);
DateTime utc = local.ToUniversalTime();
Console.WriteLine(local.Kind);
Console.WriteLine(utc.Kind);
}
}
Output
Local
Utc
How It Works
Local start. The value is built with DateTimeKind.Local.
Convert.ToUniversalTime returns a new value; local stays Local.
Kind is Utc. The result is marked as UTC.
Clock not printed. The converted hour depends on your time zone, so only the Kind is shown.
Example 2 — UTC to Local and Back
Convert a UTC value to local and back and compare to the original.
C#
using System;
class Program {
static void Main() {
DateTime utc = new DateTime(2026, 11, 18, 10, 0, 0, DateTimeKind.Utc);
DateTime back = utc.ToLocalTime().ToUniversalTime();
Console.WriteLine(back == utc);
Console.WriteLine(utc.ToUniversalTime() == utc);
}
}
Output
True
True
How It Works
Two steps. First ToLocalTime shifts the clock, then ToUniversalTime shifts it back.
Same moment. The round trip ends on the original ticks, so the first line is True.
Already UTC. Calling ToUniversalTime on a Utc value changes nothing.
Second line True. That is why calling it twice is safe.
Example 3 — Unspecified Is Treated as Local
Show that Unspecified is converted like Local, and check the offset.
C#
using System;
class Program {
static void Main() {
DateTime unspecified = new DateTime(2026, 11, 18, 10, 0, 0);
DateTime asLocal = DateTime.SpecifyKind(unspecified, DateTimeKind.Local);
Console.WriteLine(unspecified.ToUniversalTime() == asLocal.ToUniversalTime());
TimeSpan shift = unspecified - unspecified.ToUniversalTime();
Console.WriteLine(shift == TimeZoneInfo.Local.GetUtcOffset(unspecified));
}
}
Output
True
True
How It Works
No Kind set.unspecified carries no zone information.
Treated as Local. Converting it gives the same result as converting the same time marked Local.
Offset check. Local minus UTC equals the zone's offset from UTC.
Both lines True. They hold in every time zone, even though the printed hour would differ.
Frequently Asked Questions
It converts a local DateTime to UTC and sets Kind to Utc.
It is treated as local time and converted. ToLocalTime does the opposite and treats Unspecified as UTC.
It is returned unchanged.
UTC has no daylight saving changes and means the same moment everywhere, which makes comparing and sorting safe.