C# DateTime SpecifyKind() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
DateTime

Definition

In C#, every DateTime has a Kind: Utc, Local, or Unspecified. DateTime.SpecifyKind returns a copy with the same ticks and the Kind you choose.

It does not convert the time. It only says what the clock numbers mean. Use it when you know a parsed or loaded value is already UTC (or local), but its Kind says Unspecified.

This is a static member of System.DateTime. You call it with the type name, such as DateTime.SpecifyKind(...). DateTime holds a date and time of day with a Kind of Utc, Local, or Unspecified.

Syntax

Call it with the type name, a DateTime, and a DateTimeKind value.

C#
DateTime raw = new DateTime(2026, 11, 18, 10, 0, 0);   // Kind: Unspecified
DateTime utc = DateTime.SpecifyKind(raw, DateTimeKind.Utc);
DateTime loc = DateTime.SpecifyKind(raw, DateTimeKind.Local);
CallWhat it does
DateTime.SpecifyKind(dt, DateTimeKind.Utc)Label the same clock time as UTC.
DateTime.SpecifyKind(dt, DateTimeKind.Local)Label the same clock time as local time.
DateTime.SpecifyKind(dt, DateTimeKind.Unspecified)Remove the label.

Compare with ToUniversalTime(), which moves the clock by the time zone offset. SpecifyKind never moves the clock.

Library declarations
C#
public static DateTime SpecifyKind(DateTime value, DateTimeKind kind);

Parameters

ParameterDescription
valueRequired. The DateTime to copy.
kindRequired. DateTimeKind.Utc, Local, or Unspecified.

Return Value

Return ValueDescription
DateTimeA new DateTime with the same ticks as value and the chosen Kind.

C# Examples

Example 1 — Change Only the Kind

Mark an Unspecified value as Utc and check that the time itself did not change.

C#
using System;

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

How It Works

  1. Default Kind. A value built with new DateTime(y, m, d, ...) is Unspecified.
  2. Copy with a label. SpecifyKind returns a copy marked Utc; raw is untouched.
  3. Same ticks. The == operator compares ticks only, so it prints True.
  4. Not converted. Both values still read 10:00 on November 18, 2026.

Example 2 — Fix a Parsed Value

Parse text without a zone, then mark it as UTC and see the Z suffix in the round-trip format.

C#
using System;
using System.Globalization;

class Program {
    static void Main() {
        DateTime parsed = DateTime.Parse("2026-11-18 10:00:00");
        DateTime utc = DateTime.SpecifyKind(parsed, DateTimeKind.Utc);
        CultureInfo inv = CultureInfo.InvariantCulture;
        Console.WriteLine(parsed.ToString("o", inv));
        Console.WriteLine(utc.ToString("o", inv));
    }
}

How It Works

  1. Plain text. The text has no zone, so Parse returns Kind.Unspecified.
  2. Round-trip format. The "o" format shows seven fraction digits and the zone, if there is one.
  3. No suffix yet. The first line has nothing after the seconds because Kind is Unspecified.
  4. Z appears. After SpecifyKind, the second line ends with Z, which means UTC.

Example 3 — Local Label on a UTC Value

Relabel a Utc value as Local and see that the hour stays 10.

C#
using System;

class Program {
    static void Main() {
        DateTime a = new DateTime(2026, 11, 18, 10, 0, 0, DateTimeKind.Utc);
        DateTime b = DateTime.SpecifyKind(a, DateTimeKind.Local);
        Console.WriteLine(b.Hour);
        Console.WriteLine(b.Kind);
        Console.WriteLine(a == b);
    }
}

How It Works

  1. UTC start. a is 10:00 UTC.
  2. Relabeled. b has the same ticks, but now the Kind says Local.
  3. Hour stays 10. No time zone offset was added or removed.
  4. Danger. The two values now mean different real moments unless you are in UTC, yet == says they are equal.

Frequently Asked Questions

It returns a copy with the same ticks and a new Kind. It does not convert the time.
SpecifyKind only changes the label. ToUniversalTime changes the clock by the local offset.
Unspecified, Utc, and Local.
The text had no zone, so .NET does not know what it means. Use SpecifyKind or DateTimeStyles to set it.
No. DateTime is immutable. It returns a new value.

Next: Subtract()

Subtract a DateTime to get a TimeSpan, or subtract a TimeSpan to get a DateTime with System.DateTime.

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

12 people found this page helpful