问题描述
我想我的字符串格式化值与格式转换为日期类型 DD / MM / YYYY
。
I am trying to convert my string formatted value to date type with format dd/MM/yyyy
.
this.Text="22/11/2009";
DateTime date = DateTime.Parse(this.Text);
这是什么问题?它有哪些要求的IFormatProvider
第二个覆盖。这是什么? 不要的我需要通过这个也?如果是如何使用它的这种情况?
What is the problem ?It has a second override which asks for IFormatProvider
. What is this? Do I need to pass this also? If Yes how to use it for this case?
修改
之间有什么区别解析
和 ParseExact
?
编辑2
Slaks和萨姆的两个答案都为我工作,目前用户提供输入,但这会被我放心,它们是有效的使用maskTextbox。
Both answers of Slaks and Sam are working for me, currently user is giving the input but this will be assured by me that they are valid by using maskTextbox.
哪个答案是更好地考虑到各方面的类似类型的安全性,性能什么的,你觉得像
Which answer is better considering all aspects like type saftey, performance or something you feel like
推荐答案
使用 DateTime.ParseExact
。
this.Text="22/11/2009";
DateTime date = DateTime.ParseExact(this.Text, "dd/MM/yyyy", null);
这篇关于字符串未被识别为有效的DateTime"格式DD / MM / YYYY"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!