I have a doubt about this code. I would check if two times have a difference lower than 7 seconds.
static void Main(string[] args)
{
List<DateTime> logDates = new List<DateTime>();
//Define regex string
string pattern = @"(?<logDate>(\d){4}-(\d){2}-(\d){2}\s(\d){2}:(\d){2}:(\d){2})";
Regex reg = new Regex(pattern);
try
{ // Open the text file using a stream reader.
using (StreamReader sr = new StreamReader("C:\\test.txt"))
{
// Read the stream to a string, and write the string to the console.
String logContent = sr.ReadToEnd();
Console.WriteLine(logContent);
//run regex
MatchCollection matches = reg.Matches(logContent);
//iterate over matches
foreach (Match m in matches)
{
DateTime logTime = DateTime.Parse(m.Groups["logDate"].Value);
//logDates.Add(logTime);
Console.WriteLine("TIME:" + logTime.TimeOfDay);
}
#if DEBUG
Console.WriteLine("Press enter to close...");
Console.ReadLine();
#endif
}
}
catch (Exception e)
{
Console.WriteLine("The file could not be read:");
Console.WriteLine(e.Message);
}
}
This code open corretly the txt file (test.txt), read the date and print to console.
MY QUESTION IS: How can check if two times (TWO AT ONCE) have a difference lower than 7 seconds?
EDIT: Furthermore would be good, if i have a message to say it's OK or NOT OK.
Regards