C# DateTimePicker 最大日期范围

发布于 2024-10-08 23:19:04 字数 158 浏览 0 评论 0原文

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

感谢您的帮助。 晶晶

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 that 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无声无音无过去 2024-10-15 23:19:04

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

更新:
马蒂尼奥是正确的。来自 MSDN:

一些日历,例如
UmAlQuraCalendar,支持上层
早于的日期范围
最大值。在这些情况下,试图
访问变量中的 MaxValue
赋值或格式化和解析
操作可能会抛出一个
参数超出范围异常。相当
比检索的值
DateTime.MaxValue,可以检索
特定文化的价值
最新有效日期值
System.Globalization.CultureInfo.DateTimeFormat.Calendar.MaxSupportedDateTime
财产。

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文