Steps to do:
1) Declare a list of DateTime:
2) Declare start time and end time
3) Declare counter
4) define while loop
4a) Add second in each iteration of loop till start time is less then end time
4b) increase counter
5) display dates in time format
List<DateTime> myList = new List<DateTime>();
DateTime starttime = DateTime.Today;
DateTime endtime = starttime.AddDays(1).AddSeconds(-1);
int i = 0;
while(starttime<endtime)
{
starttime = starttime.AddSeconds(i);
myList.Add(starttime);
i++;
}
foreach(DateTime tm in myList)
Console.WriteLine(tm.ToString("HH:mm:ss"));
That's all!
For further details, please see:
DateTime Struct (System) | Microsoft Docs[
^]
DateTime.AddSeconds(Double) Method (System) | Microsoft Docs[
^]
Standard date and time format strings | Microsoft Docs[
^]
Custom date and time format strings | Microsoft Docs[
^]