How to Create a DateTime for a Set Date and Time in UTC in C#
new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc) creates a DateTime for a date and time you choose, marked as UTC. Leave out the last argument, and the DateTime doesn't say which time zone it's in.
Microsoft's reference for this constructor: Initializes a new instance of the DateTime structure to the specified year, month, day, hour, minute, second, and Coordinated Universal Time (UTC) or local time. A DateTime doesn't store an offset from UTC. Its Kind says what its numbers mean, and you set it with the constructor's last argument: One of the enumeration values that indicates whether year, month, day, hour, minute and second specify a local time, Coordinated Universal Time (UTC), or neither. Microsoft's guide to the date and time types recommends UTC: When saving or sharing DateTime data, use UTC and set the DateTime value's Kind property to DateTimeKind.Utc.
Syntax
DateTime <name> = new(<year>, <month>, <day>, <hour>, <minute>, <second>, DateTimeKind.Utc);
| Part | What it is |
|---|---|
<year> | The year (1 through 9999). |
<month> | The month (1 through 12). |
<day> | The day (1 through the number of days in month). |
<hour> | The hours (0 through 23). |
<minute> | The minutes (0 through 59). |
<second> | The seconds (0 through 59). |
DateTimeKind.Utc | Marks the numbers as UTC. The other values are Local and Unspecified |
The ranges in italics are the reference's own words. new(...) can leave out the type name, because DateTime <name> on the left already gives it. new DateTime(...) is the same constructor with the type written out.
The Example
A console app called UtcDateTimeCreate creates the start of an event, 15 January 2027 at 16:30:00 UTC. It prints the value with its Kind, reads the date, the day of the week and the time back from it, and then creates the same numbers without a kind, to compare.
Prerequisites
- The .NET 10 SDK.
dotnet --versionprints a version that starts with10.0.
Step 1: Create a Console App
dotnet new console -n UtcDateTimeCreate
cd UtcDateTimeCreate
The template "Console App" was created successfully.
Processing post-creation actions...
Restoring /Users/you/source/UtcDateTimeCreate/UtcDateTimeCreate.csproj:
Determining projects to restore...
Restored /Users/you/source/UtcDateTimeCreate/UtcDateTimeCreate.csproj (in 46 ms).
Restore succeeded.
dotnet new console -n UtcDateTimeCreate creates a folder named UtcDateTimeCreate with a project file and a Program.cs, and cd moves into it. Everything this example uses is part of .NET, so there's no package to add. Open the folder in VS Code, or UtcDateTimeCreate.csproj in Visual Studio.
Step 2: Write the Code
Replace everything in Program.cs. First the DateTime:
// 15 January 2027 at 16:30:00, and the last argument says it's UTC.
DateTime start = new(2027, 1, 15, 16, 30, 0, DateTimeKind.Utc);
The numbers go from the largest unit to the smallest: year, month, day, hour, minute, second. DateTimeKind.Utc marks them as UTC.
Then print it:
CultureInfo invariant = CultureInfo.InvariantCulture;
Console.WriteLine($"Start: {start.ToString("O", invariant)}");
Console.WriteLine($"Kind: {start.Kind}");
Console.WriteLine($"Date: {start.Year}-{start.Month:00}-{start.Day:00}, a {start.DayOfWeek}");
Console.WriteLine($"Time: {start.Hour}:{start.Minute:00}");
ToString("O", invariant) prints the full date and time in a fixed format, which ends with Z for a UTC DateTime. CultureInfo comes from the System.Globalization namespace, hence the using line at the top. Year, Month, Day, DayOfWeek, Hour and Minute read the parts back, and :00 prints a number with at least two digits.
Last, the same numbers without a kind:
// The same numbers without a kind: the DateTime doesn't say it's UTC.
DateTime noKind = new(2027, 1, 15, 16, 30, 0);
Console.WriteLine($"Without a kind: {noKind.ToString("O", invariant)}, Kind {noKind.Kind}");
This constructor takes no kind argument.
Step 3: Run It
Run it in VS Code's terminal, or press Ctrl+F5 in Visual Studio:
dotnet run
Start: 2027-01-15T16:30:00.0000000Z
Kind: Utc
Date: 2027-01-15, a Friday
Time: 16:30
Without a kind: 2027-01-15T16:30:00.0000000, Kind Unspecified

start printed as 2027-01-15T16:30:00.0000000Z, with Kind Utc: 15 January 2027, a Friday, at 16:30. The same numbers without a kind printed without the Z, and with Kind Unspecified. The reference for that constructor: The Kind property is initialized to Unspecified. Nothing in that value says it's UTC.
The Complete File

using System.Globalization;
// 15 January 2027 at 16:30:00, and the last argument says it's UTC.
DateTime start = new(2027, 1, 15, 16, 30, 0, DateTimeKind.Utc);
CultureInfo invariant = CultureInfo.InvariantCulture;
Console.WriteLine($"Start: {start.ToString("O", invariant)}");
Console.WriteLine($"Kind: {start.Kind}");
Console.WriteLine($"Date: {start.Year}-{start.Month:00}-{start.Day:00}, a {start.DayOfWeek}");
Console.WriteLine($"Time: {start.Hour}:{start.Minute:00}");
// The same numbers without a kind: the DateTime doesn't say it's UTC.
DateTime noKind = new(2027, 1, 15, 16, 30, 0);
Console.WriteLine($"Without a kind: {noKind.ToString("O", invariant)}, Kind {noKind.Kind}");
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Leaving out DateTimeKind.Utc | new(2027, 1, 15, 16, 30, 0) gave Kind Unspecified, and it printed without the Z | Pass DateTimeKind.Utc as the last argument, as the example does |
| Writing midnight as hour 24 | new(2026, 12, 31, 24, 0, 0, DateTimeKind.Utc) stopped the program: Unhandled exception. System.ArgumentOutOfRangeException: Hour, Minute, and Second parameters describe an un-representable DateTime. The reference: The hours (0 through 23). | Midnight at the end of a day is 00:00 on the next day: new(2027, 1, 1, 0, 0, 0, DateTimeKind.Utc) printed 2027-01-01T00:00:00.0000000Z |
| Writing the day before the month | new(2027, 15, 1, 16, 30, 0, DateTimeKind.Utc), meant as 15 January, stopped the program: Unhandled exception. System.ArgumentOutOfRangeException: Year, Month, and Day parameters describe an un-representable DateTime. The reference: The month (1 through 12). | Write the year, then the month, then the day: new(2027, 1, 15, 16, 30, 0, DateTimeKind.Utc) |
FAQ
Does == notice that one DateTime is UTC and the other isn't?
No. It compares only the date and time:
DateTime utc = new(2027, 1, 15, 16, 30, 0, DateTimeKind.Utc);
DateTime noKind = new(2027, 1, 15, 16, 30, 0);
Console.WriteLine($"Kinds: {utc.Kind} and {noKind.Kind}");
Console.WriteLine($"utc == noKind: {utc == noKind}");
Kinds: Utc and Unspecified
utc == noKind: True
The Equals reference says it plainly: The current instance and value are equal if their Ticks property values are equal. Their Kind property values are not considered in the test for equality. And the reference for ==: Before comparing DateTime objects, make sure that the objects represent times in the same time zone.
How do I mark a DateTime I already have as UTC?
DateTime.SpecifyKind returns a copy with the kind you choose:
using System.Globalization;
DateTime noKind = new(2027, 1, 15, 16, 30, 0);
// Same date and time, now marked as UTC.
DateTime utc = DateTime.SpecifyKind(noKind, DateTimeKind.Utc);
Console.WriteLine($"{utc.ToString("O", CultureInfo.InvariantCulture)}, Kind {utc.Kind}");
2027-01-15T16:30:00.0000000Z, Kind Utc
The time stayed 16:30, and the kind became Utc. It doesn't convert anything, in the reference's words: The returned DateTime value does not represent the same instant in time as the value parameter, and SpecifyKind is not a time zone conversion method. Instead, it leaves the time specified by the value parameter unchanged, and sets the Kind property to kind. So use it only for a value you know is already in UTC.
Conclusion
new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc) creates a fixed date and time in UTC, with Kind set to Utc. Write the parts from the year down to the second, keep the hour between 0 and 23, and don't leave out the kind, because == won't tell you when it's missing.
Additional Resources
DateTimeConstructors — every constructor, the ranges of each part, and thekindargument.DateTimeKindEnum —Utc,LocalandUnspecified.DateTime.SpecifyKindMethod — marks an existing value with a kind.- Choose between DateTime, DateOnly, DateTimeOffset, TimeSpan, TimeOnly, and TimeZoneInfo — when to use which date and time type.
