DateTimeOffset localTime = DateTimeOffset.Now; Console.WriteLine(localTime.ToString());
DateTimeOffset dateTime = new DateTimeOffset(2021, 11, 1, 0, 0, 0, new TimeSpan(3, 0, 0)); Console.WriteLine(dateTime.ToString());
DateTimeOffset originalTime = new DateTimeOffset(2021, 1, 1, 0, 0, 0, TimeSpan.Zero); TimeZoneInfo targetTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"); DateTimeOffset convertedTime = TimeZoneInfo.ConvertTime(originalTime, targetTimeZone); Console.WriteLine(convertedTime.ToString());This code will convert a DateTimeOffset value representing January 1, 2021, at 12:00 AM UTC to the Central Standard Time zone. These examples are part of the System namespace, specifically the System.DateTimeOffset class, which is included in the .NET framework libraries.