如何将短日期字符串转换回DateTime对象? [英] How do I convert a short date string back to a DateTime object?

查看:121
本文介绍了如何将短日期字符串转换回DateTime对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个DateTime对象,我使用ToShortDateString()函数后保存到一个文件;字符串看起来像12/15/2009。现在我坚持这个部分,我想用这些字符串初始化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对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆