问题描述
我希望以下内容将2030日期写入targetDate。它没有。它给出了1930年的日期。
Dim ci As CultureInfo = CurrentThread.CurrentCulture.Clone
ci.Calendar.TwoDigitYearMax = 2099
DateTime.TryParse ( 12/8/30,ci,DateTimeStyles.AssumeLocal,targetDate)
但是,如果我将当前文化设置为克隆,那么我将得到预期的(并且必需的)2030日期。但前提是代码在控制台应用程序(Win7 Professional上的Framework 2或Framework 4.5)中运行。
Dim ci As CultureInfo = CurrentThread.CurrentCulture.Clone
ci.Calendar.TwoDigitYearMax = 2099
CurrentThread.CurrentCulture = ci
DateTime.TryParse( 12/8/30,ci,DateTimeStyles.AssumeLocal,targetDate)
如果第二个片段是运行服务器在Web应用程序(Framework 2,Win7 Professional)中,targetDate是_always_ 20世纪(19xx)日期。这不是所希望的行为,似乎与文件相矛盾。
两个控制台应用程序。和Web应用程序。在相同的(开发)机器上运行。运行之间不会改变文化设置。
其他人看过这个吗?
你有没有解释发生了什么?
I would expect the following to write a 2030 date into targetDate. It doesn't. It gives a 1930 date.
Dim ci As CultureInfo = CurrentThread.CurrentCulture.Clone ci.Calendar.TwoDigitYearMax = 2099 DateTime.TryParse("12/8/30", ci, DateTimeStyles.AssumeLocal, targetDate)
However if I set current culture to the clone then I get the expected (and required) 2030 date. But only if the code is running in a console app (Framework 2 or Framework 4.5 on Win7 Professional).
Dim ci As CultureInfo = CurrentThread.CurrentCulture.Clone ci.Calendar.TwoDigitYearMax = 2099 CurrentThread.CurrentCulture = ci DateTime.TryParse("12/8/30", ci, DateTimeStyles.AssumeLocal, targetDate)
If the second fragment is run server side in a web app (Framework 2, Win7 Professional) then targetDate is _always_ a 20th century (19xx) date. This not desired behaviour and seems to
contradict the documentation.
Both the console apps. and the Web app. are run on the same (development) machine. Culture settings are not altered between runs.
Anyone else seen this?
Have you an explanation for what's going on?
这篇关于文化日历TwoDigitYearMax被.Net Date Parse忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!