简体   繁体   中英

c# TimeOfDay not between 2 timespans

Having today's date for example: DateTime.Now

And 2 TimeSpan that represents two periods of time

DateTime mydate = DateTime.Now;

TimeSpan start = TimeSpan.Parse("14:00:00");
TimeSpan end =   TimeSpan.Parse("15:00:00");

// TO DO: 

How to check that mydate time (TimeOfDay) is not between start and end range.

Basically check if the hours, minutes, seconds are between 14:00 and 15:00 or outside this range.

UPDATE:

The right condition is: mydate.TimeOfDay <= start || mydate.TimeOfDay >= end mydate.TimeOfDay <= start || mydate.TimeOfDay >= end

Comparing them seems to work seams to work. TimeOfDay is a TimeSpan just like start and end

Console.WriteLine(mydate.TimeOfDay <= start || mydate.TimeOfDay >= end);

Fiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM