C# DateTime ToUniversalTime() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
DateTime

Definition

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
CallWhat 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

ParameterDescription
NoneToUniversalTime() takes no parameters.

Return Value

Return ValueDescription
DateTimeA 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);
    }
}

How It Works

  1. Local start. The value is built with DateTimeKind.Local.
  2. Convert. ToUniversalTime returns a new value; local stays Local.
  3. Kind is Utc. The result is marked as UTC.
  4. 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);
    }
}

How It Works

  1. Two steps. First ToLocalTime shifts the clock, then ToUniversalTime shifts it back.
  2. Same moment. The round trip ends on the original ticks, so the first line is True.
  3. Already UTC. Calling ToUniversalTime on a Utc value changes nothing.
  4. 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));
    }
}

How It Works

  1. No Kind set. unspecified carries no zone information.
  2. Treated as Local. Converting it gives the same result as converting the same time marked Local.
  3. Offset check. Local minus UTC equals the zone's offset from UTC.
  4. 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.
Use TimeZoneInfo.ConvertTimeToUtc(dt, zone).

Next: TryParse()

Try to convert date text to a DateTime; returns true or false instead of throwing with System.DateTime.

TryParse() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

15 people found this page helpful