DateTime可以直接赋值给DateTimeOffset:
DateTimeOffset dtOffset = DateTime.Now;
但是下面的代码:
DateTimeOffset dtOffset = default(DateTime);
会报错:
The UTC time represented when the offset is applied must be between year 0 and 10,000
正确的解决方法(来源)是:
public static class DateTimeExtensions { public static DateTimeOffset ToDateTimeOffset(this DateTime dateTime) { return dateTime.ToUniversalTime() <= DateTimeOffset.MinValue.UtcDateTime ? DateTimeOffset.MinValue : new DateTimeOffset(dateTime); } }