#region XML Reader (Load the XML file)
XmlDocument xdoc = new XmlDocument();
xdoc.Load(root + infoFolder + "setting.xml");
#endregion
#region Find out if its time to update installation files
var DateNow = DateTime.Now.ToString("yyyy-MM-dd");
var LastUpdate = xdoc.SelectSingleNode("/Settings/TimeUpdated").InnerText;
if (DateNow.CompareTo(LastUpdate) > 0)
{
MessageBox.Show ("Last time you updated you installation files was" + LastUpdate + ". Today its " + DateNow,("Its been 14days.(or more)"));
}
#endregion
这就是我想出来的,但这只是比较'Datenow'是否高于'Lasteupdate' 我认为CompareTo不适用于约会。
我真正希望比较Datenow和Lasteupdate,如果它的14天不同,那么就显示消息框。
这是我解决问题的方法:
#region Find out if its time to update installation files
String LastUpdate = xdoc.SelectSingleNode("Knowhow/Settings/TimeUpdated").InnerText;
DateTime dt1 = DateTime.Now.AddDays(-14);
DateTime dt2 = DateTime.Parse(LastUpdate);
String DateToday = dt1.ToString("yyyy-MM-dd");
String DateINFO = dt2.ToString("yyyy-MM-dd");
if (dt1.Date > dt2.Date)
{
MessageBox.Show("Last time you updated you installation files was" + DateINFO + ". Its been Its been 14days.(or more)");
; }
else
{
MessageBox.Show("Dont need to update");
}
#endregion