C# 如何在时间间隔内执行操作

C# 如何在时间间隔内执行操作,c#,xamarin,C#,Xamarin,我正在尝试根据一天中的时间更改标签的文本 Label OpenClosedLabel=new Label(); TimeSpan T1=新的TimeSpan(13,00,00); TimeSpan T2=新的TimeSpan(00,00,00); 现在,如果DateTime.Today.TimeOfDay在T1和T2范围内,则标签应为“打开”,否则标签应为“关闭” 我试过这个,但不起作用: if(DateTime.Today.TimeOfDay>=T1&&DateTime.Today.Time

我正在尝试根据一天中的时间更改标签的文本

Label OpenClosedLabel=new Label();
TimeSpan T1=新的TimeSpan(13,00,00);
TimeSpan T2=新的TimeSpan(00,00,00);
现在,如果
DateTime.Today.TimeOfDay
T1
T2
范围内,则标签应为“打开”,否则标签应为“关闭”

我试过这个,但不起作用:


if(DateTime.Today.TimeOfDay>=T1&&DateTime.Today.TimeOfDay
DateTime.Today.TimeOfDay
将只提供日期,但

DateTime.Now.TimeOfDay
也将为您提供时间数据

所以,我想这样做:

Label OpenClosedLabel=new Label();
TimeSpan T1=新的TimeSpan(13,00,00);
TimeSpan T2=新的TimeSpan(23,59,59);
var Now=DateTime.Now.TimeOfDay;

OpenClosedLabel.Text=(Now>=T1&&Now这是一个移动应用程序吗?@SeM是的。那么问题是什么,添加if条件并检查今天的时间是否在给定范围内。@SeM,我尝试了类似于
if的方法(DateTime.Today.TimeOfDay>=T1&DateTime.Today.TimeOfDay
DateTime.Today
将只包含日期。
DateTime.Now.TimeOfDay
将包含时间