Format dates and offsets predictably in C#
Date formatting and date parsing solve different problems. Construct or parse the value first, then choose the representation its reader needs.
Use DateTimeOffset when an offset is part of the value. A formatted offset does not identify a time zone or its daylight-saving rules.
Format a known value
Create a .NET console project and use this Program.cs:
using System.Globalization;
var timestamp = new DateTimeOffset(2026, 11, 24, 16, 5, 7, TimeSpan.FromHours(10));
Console.WriteLine(timestamp.ToString("yyyy-MM-dd HH:mm:ss zzz",
CultureInfo.InvariantCulture));
Console.WriteLine(timestamp.ToString("O", CultureInfo.InvariantCulture));
Console.WriteLine(timestamp.ToString("d MMMM yyyy", CultureInfo.GetCultureInfo("en-AU")));
Run dotnet run. The first line is 2026-11-24 16:05:07 +10:00. The second is 2026-11-24T16:05:07.0000000+10:00. The third is 24 November 2026.
Pick tokens deliberately
MM means month. mm means minute. HH is a 24-hour clock, while hh needs an AM/PM marker to avoid ambiguity. yyyy keeps the four-digit year. The round-trip O format is useful when a string must preserve the offset and precision.
Avoid parsing inputs such as 08/09/26 without a known format and culture. Use TryParseExact for a fixed input contract. For storage and APIs, prefer typed date/time fields or a documented round-trip representation. Reserve localized month names and punctuation for display.
Official references

Author: Herman Schoenfeld