Home C# DateTime Methods SpecifyKind() C# DateTime SpecifyKind() Method 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.
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); Call What 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 public static DateTime SpecifyKind(DateTime value, DateTimeKind kind); Parameters Parameter Description value Required. The DateTime to copy. kind Required. DateTimeKind.Utc, Local, or Unspecified.
Return Value Return Value Description DateTime A new DateTime with the same ticks as value and the chosen Kind.
Important
Label, not conversion: SpecifyKind(dt, Utc) keeps 10:00 as 10:00. If the value was really local time, you have just told the program a lie. Use ToUniversalTime() to convert real local time to UTC.
C# Examples 1. Mark as UTC 2. Parsed text 3. No clock shift Example 1 — Change Only the Kind Mark an Unspecified value as Utc and check that the time itself did not change.
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 Default Kind. A value built with new DateTime(y, m, d, ...) is Unspecified.Copy with a label. SpecifyKind returns a copy marked Utc; raw is untouched.Same ticks. The == operator compares ticks only, so it prints True.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.
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));
}
} 2026-11-18T10:00:00.0000000
2026-11-18T10:00:00.0000000Z How It Works Plain text. The text has no zone, so Parse returns Kind.Unspecified.Round-trip format. The "o" format shows seven fraction digits and the zone, if there is one.No suffix yet. The first line has nothing after the seconds because Kind is Unspecified.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.
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 UTC start. a is 10:00 UTC.Relabeled. b has the same ticks, but now the Kind says Local.Hour stays 10. No time zone offset was added or removed.Danger. The two values now mean different real moments unless you are in UTC, yet == says they are equal.Frequently Asked Questions What does DateTime.SpecifyKind do? It returns a copy with the same ticks and a new Kind. It does not convert the time.
What is the difference between SpecifyKind and ToUniversalTime? SpecifyKind only changes the label. ToUniversalTime changes the clock by the local offset.
What are the DateTimeKind values? Unspecified, Utc, and Local.
Why is the Kind of a parsed date Unspecified? The text had no zone, so .NET does not know what it means. Use SpecifyKind or DateTimeStyles to set it.
Does SpecifyKind change the original? 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 Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion