C# DateTime ToLocalTime() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
DateTime

Definition

In C#, DateTime.ToLocalTime() converts a UTC value to the local time of the computer that runs the code. The result has Kind.Local.

The answer depends on the machine's time zone, so the examples below test the rules (kind and offset) instead of printing a clock value that would change.

This is an instance member of System.DateTime. You call it on a DateTime value, such as dt.ToLocalTime(...). 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 utc = new DateTime(2026, 11, 18, 10, 0, 0, DateTimeKind.Utc);
DateTime local = utc.ToLocalTime();   // Kind is Local
CallWhat it does
utc.ToLocalTime()UTC to local time. Kind becomes Local.
local.ToLocalTime()A Local value is returned unchanged.
unspecified.ToLocalTime()An Unspecified value is treated as UTC and converted.

For other zones, use TimeZoneInfo.ConvertTimeFromUtc(utc, zone). ToLocalTime only knows the zone of the computer.

Library declarations
C#
public DateTime ToLocalTime();

Parameters

ParameterDescription
NoneToLocalTime() takes no parameters.

Return Value

Return ValueDescription
DateTimeA new DateTime in local time with Kind.Local.

C# Examples

Example 1 — Utc to Local

Convert a UTC value and read the Kind of both values.

C#
using System;

class Program {
    static void Main() {
        DateTime utc = new DateTime(2026, 11, 18, 10, 0, 0, DateTimeKind.Utc);
        DateTime local = utc.ToLocalTime();
        Console.WriteLine(utc.Kind);
        Console.WriteLine(local.Kind);
    }
}

How It Works

  1. Start in UTC. The value is built with DateTimeKind.Utc.
  2. New value. ToLocalTime returns a copy; utc itself stays Utc.
  3. Kind is Local. The result is marked as local time.
  4. No clock printed. The actual hour would depend on your time zone, so the code prints the Kind instead.

Example 2 — Check the Offset

Prove that the shift equals the zone's UTC offset.

C#
using System;

class Program {
    static void Main() {
        DateTime utc = new DateTime(2026, 11, 18, 10, 0, 0, DateTimeKind.Utc);
        DateTime local = utc.ToLocalTime();
        TimeSpan shift = local - utc;
        Console.WriteLine(shift == TimeZoneInfo.Local.GetUtcOffset(utc));
    }
}

How It Works

  1. Subtract the two values. local - utc gives the shift the conversion applied.
  2. Zone offset. GetUtcOffset(utc) asks the local zone how far it is from UTC at that moment.
  3. They match. The comparison is True on every computer.
  4. Works in any zone. In a UTC+5:30 zone the shift is 5.5 hours, in UTC-5 it is minus five hours.

Example 3 — Local and Unspecified Inputs

Show how Unspecified and Local inputs behave.

C#
using System;

class Program {
    static void Main() {
        DateTime unspecified = new DateTime(2026, 11, 18, 10, 0, 0);
        DateTime asUtc = DateTime.SpecifyKind(unspecified, DateTimeKind.Utc);
        Console.WriteLine(unspecified.ToLocalTime() == asUtc.ToLocalTime());

        DateTime local = new DateTime(2026, 11, 18, 10, 0, 0, DateTimeKind.Local);
        Console.WriteLine(local.ToLocalTime() == local);
    }
}

How It Works

  1. No Kind set. unspecified has Kind.Unspecified.
  2. Treated as UTC. Converting it gives the same result as converting the same time marked Utc.
  3. Already local. A Local value passes through ToLocalTime unchanged.
  4. Both lines True. These rules are why you should set Kind before converting.

Frequently Asked Questions

It converts a UTC DateTime to the local time zone of the computer and sets Kind to Local.
ToLocalTime treats it as UTC and converts it. ToUniversalTime treats Unspecified as local.
It is returned unchanged.
The result depends on the computer time zone, so the tutorial checks Kind and offset rules that never change.
Use TimeZoneInfo.ConvertTimeFromUtc(utc, zone).

Next: ToLongDateString()

Get the date part as long text with weekday and month name, using the current culture with System.DateTime.

ToLongDateString() 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.

8 people found this page helpful