C# 比较LastWriteTime与.txt文件
我想比较一下计算机上文件的LastWriteTime和服务器上的.txt文件(例如),我有类似的东西,但上面说的是日期不一样C# 比较LastWriteTime与.txt文件,c#,file,compare,C#,File,Compare,我想比较一下计算机上文件的LastWriteTime和服务器上的.txt文件(例如),我有类似的东西,但上面说的是日期不一样 WebClient Download = new WebClient(); string serwer_date = Download.DownloadString("http://www.vmr.cba.pl/VMR/config_date.txt"); string DateServer = serwer_date;
WebClient Download = new WebClient();
string serwer_date = Download.DownloadString("http://www.vmr.cba.pl/VMR/config_date.txt");
string DateServer = serwer_date;
path = "yo.txt";
DateTime test = new DateTime();
test = File.GetLastWriteTime(path);
test.ToString("dd-MM-yy-HH:MM");
if (String.Equals(test, DateServer))
{
MessageBox.Show("No cheat");
}
else
{
MessageBox.Show("cheat ;c");
您调用了
ToString
函数,但没有从中得到结果ToString
不会修改当前对象。
DateTime的返回值。ToString
是当前DateTime对象值的字符串表示形式,由format指定
您需要修改代码的这一部分,如下所示:
string dateInString = test.ToString("dd-MM-yy-HH:MM");
if (String.Equals(dateInString, DateServer))
{
MessageBox.Show("No cheat");
}
也许和时区有关。。说明返回时间是当地时间。观察得不错。我错过了那个。