开发者

C# DateTimePicker Max Date range

I am using datetimepicker which displays the date(which is retrieved from the database). I have run my application on a few machines and I have found that on Windows XP SP2, the max date t开发者_高级运维hat can be retrieved and displayed is 2020, but for later versions of the OS the max date can be highier, e.g. 2999. Does anyone know about this issue?

Thank you for your help. Jing Jing


You can use the DateTime.MaxValue property to retrieve the largest possible date, dependent on the system. If you are having problems reading dates due to overflow, you can use the DateTime.TryParse() methods to attempt a read of the value without throwing an exception.

UPDATE: Martinho is correct. From MSDN:

Some calendars, such as the UmAlQuraCalendar, support an upper date range that is earlier than MaxValue. In these cases, trying to access MaxValue in variable assignments or formatting and parsing operations can throw an ArgumentOutOfRangeException. Rather than retrieving the value of DateTime.MaxValue, you can retrieve the value of the specified culture's latest valid date value from the System.Globalization.CultureInfo.DateTimeFormat.Calendar.MaxSupportedDateTime property.

So, use the System.Globalization.CultureInfo.DateTimeFormat.Calendar.MaxSupportedDateTime field to get the maximum date value supported by the system.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜