检查字符串中的值是否更接近系统时间

use*_*720 0 c# time file

我需要检查字符串中的值是否来自文件,是否更接近系统时间.我不想检查它是否等于.在系统时间范围内,该值应为+5或-5分钟.

e.g. If value from file is : 060700, and system time is 060500 OR 060900 
     I want to return a true
Run Code Online (Sandbox Code Playgroud)

我可以将文件时解析为:

DateTime filTime = DateTime.ParseExact(time, "HH:mm:ss", System.Globalization.CultureInfo.CurrentCulture);
Run Code Online (Sandbox Code Playgroud)

然后获取当前系统时间:

DateTime curTime = DateTime.Now;
Run Code Online (Sandbox Code Playgroud)

但是现在应该如何检查+5或-5分钟范围.请指教.

Tim*_*ter 5

TimeSpan diff = curTime - fileTime;
bool inRange = diff.Duration().TotalMinutes <= 5;
Run Code Online (Sandbox Code Playgroud)

TimeSpan.Duration 返回绝对时间跨度.