C# DateTimePicker 最大日期范围

标签 c# range datetimepicker maxdate

我正在使用显示日期(从数据库中检索)的 datetimepicker。我在几台机器上运行了我的应用程序,我发现在 Windows XP SP2 上,可以检索和显示的最大日期是 2020 年,但对于更高版本的操作系统,最大日期可能更高,例如2999.有人知道这个问题吗?

感谢您的帮助。 晶晶

最佳答案

您可以使用 DateTime.MaxValue 属性来检索可能的最大日期,具体取决于系统。如果由于溢出而无法读取日期,可以使用 DateTime.TryParse() 方法尝试读取值而不引发异常。

更新: 马丁尼奥是对的。来自 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.

因此,使用 System.Globalization.CultureInfo.DateTimeFormat.Calendar.MaxSupportedDateTime 字段来获取系统支持的最大日期值。

关于C# DateTimePicker 最大日期范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4511829/

相关文章:

c# - 如何通过 WMI 获取我系统上的所有智能卡读卡器?

mysql - 自动计算表中的范围(mysql)

javascript - Datetimepicker不显示默认日期值

swift - 快速解析多范围请求响应

date - 过滤范围日期elasticsearch

javascript - Sencha Touch 2 日期选择器组件和 css : how to display hidden column names?

java - 如何使用 fragment 添加时间选择器?

c# - 如何在 C# 控制台应用程序中打印双引号 (")

c# - 如何配置 AutoMapper 在映射时不检查成员列表?

c# - Entity Framework 模型中的更新列表