I have a situation in which I need to set up a re-occuring time span (for this example, 6 PM – 6 AM is the span of time)
Date is not relevent to this. It is presumed to be a check every single day.
I am having trouble wrapping my head around how to do it because using DateTime.UtcNow does yield me the right time, but it does not yield the right day. However using DateTime.MinValue does not yield the current time. And I was not able to set the Date manually. I have explored the other posts on stack overflow, and I’m just misunderstanding something, I think.. but this is my paltry code at the moment…
var start = DateTime.MinValue.Date.Add(new TimeSpan(18, 0, 0));
var end = DateTime.MinValue.Date.Add(new TimeSpan(6, 0, 0));
var timezone = TimeZone.CurrentTimeZone.GetUtcOffset(start);
var now = DateTime.UtcNow;
now.Date = DateTime.MinValue;
// is right now greater than 6pm est?
Console.WriteLine(start.TimeOfDay < now);
Console.WriteLine(end < DateTime.UtcNow);
Console.WriteLine(start.ToShortTimeString());
Console.WriteLine(DateTime.UtcNow.TimeOfDay);
Console.WriteLine(timezone.ToString());
Console.ReadLine();
I am not sure as what you want to achieve but for a check won’t something like this do for you