I have the following code in an ASP.NET MVC3 Controller:
public PartialViewResult GetCalendar(int? month, int? year)
{
var test = new DateTime((y
I just had this issue, introduced by the part of my team that's on a negative UTC zone...
What chamila_c posted is the real reason why this happens, but I needed a quick fix.
To "solve it" I basically created this extension:
public static class DateTimeExtensions
{
public static DateTimeOffset ToDateTimeOffset(this DateTime dateTime)
{
return dateTime.ToUniversalTime() <= DateTimeOffset.MinValue.UtcDateTime
? DateTimeOffset.MinValue
: new DateTimeOffset(dateTime);
}
}
you might also want to check against the MaxValue.