这是错的,有一个错误 [英] is this wrong, there's an error
本文介绍了这是错的,有一个错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
DateTime dateTo = DateTime.ParseExact(tb_DateTo.Text,MM / dd / yyyy,CultureInfo.InvariantCulture);
string dateToFormat = dateFrom.ToString(dd / MM / yyyy) ;
DateTime dateTo = DateTime.ParseExact(tb_DateTo.Text, "MM/dd/yyyy", CultureInfo.InvariantCulture);
string dateToFormat = dateFrom.ToString("dd/MM/yyyy");
推荐答案
试试这个
Try this
DateTime dateTo = DateTime.ParseExact(tb_DateTo.Text.Trim(), "MM/dd/yyyy", CultureInfo.InvariantCulture);
string dateToFormat = dateTo.ToString("dd/MM/yyyy");
这不一定是错的。我怀疑你得到一个FormatException?使用 ParseExact 时[ ^ ],输入字符串必须完全相同匹配指定的格式,任何不同的东西,解析都会失败。
例如:
It's not necessarily wrong. I suspect you're getting a FormatException? When using ParseExact[^], the input string must exactly match the specified format, anything different and the parse will fail.
For example:
DateTime.ParseExact("02/04/2014", "MM/dd/yyyy", CultureInfo.InvariantCulture)
将解析很好。
但是,这个:
Will parse just fine.
However, this:
DateTime.ParseExact("02/04/2014 12:00:00", "MM/dd/yyyy", CultureInfo.InvariantCulture)
将失败
will fail
这篇关于这是错的,有一个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文