CSharp examples for System:DateTimeOffset
Converts an existing to a but normalizes DateTimeOffset
using System;/*from w w w . j a v a 2 s. c o m*/ public class Main{ public static DateTimeOffset ToDateTimeOffset(this DateTime dateTime, TimeSpan offset) { return new DateTimeOffset(DateTime.SpecifyKind(dateTime, DateTimeKind.Unspecified) , offset); } /// <summary> /// Converts an existing <see cref="DateTime"/> to a <see cref="DateTimeOffset"/> but normalizes the <see cref="DateTimeKind"/> /// so that comparisons of converted <see cref="DateTime"/> instances retain the UTC/local agnostic behavior. /// </summary> public static DateTimeOffset ToDateTimeOffset(this DateTime dateTime) { return dateTime.ToDateTimeOffset(TimeSpan.Zero); } }