如何将短日期字符串转换回DateTime对象? [英] How do I convert a short date string back to a DateTime object?
本文介绍了如何将短日期字符串转换回DateTime对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
您可以尝试
DateTime date = DateTime.ParseExact(12/15/2009,MM / dd / yyyy,null);
看看
I have 2 DateTime objects, which I save to a file after using the ToShortDateString() function; the strings look like "12/15/2009". I am stuck on this part now, I want to initialize DateTime object(s) with these strings so I can compare the timespan between the date dates. Any help appreciated.
解决方案
You can try
DateTime date = DateTime.ParseExact("12/15/2009", "MM/dd/yyyy", null);
Have a look at
- DateTime.ParseExact Method (String, String, IFormatProvider)
- Easy String to DateTime, DateTime to String and Formatting
这篇关于如何将短日期字符串转换回DateTime对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文