如何将2个字符串与日期值进行比较 [英] how to compare 2 string with date value on them
本文介绍了如何将2个字符串与日期值进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友们。
我有两个日期值,它们存储在两个字符串中。我想比较这两个日期以了解更多。我可以比较一下吗?
谢谢。
hi friends.
i have two date value that they are stored in two string. i want to compare this two date to know greater.how can i compare this?
thank you.
推荐答案
你好,
试试这个。
Hello,
Try this.
DateTime date1 = Convet.ToDateTime(str1);
DateTime date2 = Convet.ToDateTime(str2);
int result = DateTime.Compare(date1, date2);
string relationship;
if (result < 0)
relationship = "is earlier than";
else if (result == 0)
relationship = "is the same time as";
else
relationship = "is later than";
这篇关于如何将2个字符串与日期值进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文