【问题标题】:Comparing LastWriteTime with .txt file将 LastWriteTime 与 .txt 文件进行比较
【发布时间】:2015-10-24 18:29:58
【问题描述】:

我想比较计算机上的文件中的 LastWriteTime 和服务器上的 .txt 文件(例如 http://www.vmr.cba.pl/VMR/config_date.txt),我有类似的东西,但它说日期不一样,但它是

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");

【问题讨论】:

  • 可能与时区有关。MSDN 声明返回时间是当地时间。

标签: c# file compare


【解决方案1】:

你调用了ToString 函数,但没有得到结果。 ToString 不会修改您当前的对象。 DateTime.ToString 的返回值是格式指定的当前 DateTime 对象的值的字符串表示形式。

https://msdn.microsoft.com/ru-ru/library/zdtaw1bw(v=vs.110).aspx

您需要像这样修改这部分代码:

string dateInString = test.ToString("dd-MM-yy-HH:MM");

if (String.Equals(dateInString, DateServer))
{
    MessageBox.Show("No cheat");
}

【讨论】:

  • 不错的观察。我错过了那个。
猜你喜欢
  • 2022-01-06
  • 2013-03-18
  • 1970-01-01
  • 1970-01-01
  • 2016-07-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多