gpt4 book ai didi

c# - 根据日期时间比较两个文件最多一分钟?

转载 作者:太空宇宙 更新时间:2023-11-03 19:31:51 25 4
gpt4 key购买 nike

我需要通过在比较时消除秒数来比较基于日期时间的两个文件直到分钟...

public class FileCompareLastwritetime : System.Collections.Generic.IEqualityComparer<System.IO.FileInfo>
{
public FileCompareLastwritetime() { }
public bool Equals(System.IO.FileInfo f1, System.IO.FileInfo f2)
{
return f1.LastWriteTime == f2.LastWriteTime;
}
public int GetHashCode(System.IO.FileInfo fi)
{
string s = String.Format("{0}", fi.LastWriteTime);
return s.GetHashCode();
}
}

最佳答案

怎么样:

public class FileCompareLastwritetime
: System.Collections.Generic.IEqualityComparer<System.IO.FileInfo> {
public FileCompareLastwritetime() { }
public bool Equals(System.IO.FileInfo f1, System.IO.FileInfo f2) {
return ToMinute(f1.LastWriteTime) == ToMinute(f2.LastWriteTime);
}
public int GetHashCode(System.IO.FileInfo fi) {
return ToMinute(fi.LastWriteTime).GetHashCode();
}
static DateTime ToMinute(DateTime value) {
return new DateTime(value.Year, value.Month, value.Day,
value.Hour, value.Minute, 0, value.Kind);
}
}

关于c# - 根据日期时间比较两个文件最多一分钟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4428302/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com