Datetime 转换失败【非常邪门】

星际 星际 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
大家好,目前遇到一个邪门的问题,环境:.Net Framework 2.0 + Windows 2000

以下是测试程序做的代码片段:


textBox1.AppendText(DateTime.Now.ToString() + Environment.NewLine);
textBox1.AppendText("Try Convert datetime:2011/8/1 14:22:30"+Environment.NewLine);
try
{
textBox1.AppendText(Convert.ToDateTime("2011/8/1 14:22:30").ToString() + Environment.NewLine);
textBox1.AppendText("Try Convert datetime successfully" + Environment.NewLine);
}
catch(Exception ex)
{
textBox1.AppendText("Try Convert datetime has error:" + ex.ToString() + Environment.NewLine);
}


输出结果:

2011/08/01 16:44:03
Try Convert datetime:2011/8/1 14:22:30
Try Convert datetime has error:System.IndexOutOfRangeException: 索引超出了数组界限。
在 System.Globalization.DateTimeFormatInfo.InsertHash(TokenHashValue[] hashTable, String str, TokenType tokenType, Int32 tokenValue)
在 System.Globalization.DateTimeFormatInfo.CreateTokenHashTable()
在 System.Globalization.DateTimeFormatInfo.Tokenize(TokenType TokenMask, TokenType& tokenType, Int32& tokenValue, __DTString& str)
在 System.__DTString.GetSeparatorToken(DateTimeFormatInfo dtfi)
在 System.DateTimeParse.Lex(DS dps, __DTString& str, DateTimeToken& dtok, DateTimeRawInfo& raw, DateTimeResult& result, DateTimeFormatInfo& dtfi)
在 System.DateTimeParse.TryParse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles, DateTimeResult& result)
在 System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
在 System.DateTime.Parse(String s, IFormatProvider provider)
在 System.Convert.ToDateTime(String value)
在 TestTime.Form1.button1_Click(Object sender, EventArgs e)


为什么时间格式不能被识别?查看了区域设置,都是选择的中国。邪门了。。。
...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
星际
C# 111,130 成员 642,540 内容