C#通过Webservice判断当前时间是否在这个时间段内。急,在线等!!!

2025-04-02 10:42:43
推荐回答(2个)
回答1:

[WebMethod(Description = "返回白天还是黑夜")]
public int DayOrNight(string datetime)
{
if (System.DateTime.Now.TimeOfDay >= System.Convert.ToDateTime(datetime).TimeOfDay && System.DateTime.Now.TimeOfDay < System.Convert.ToDateTime(datetime).TimeOfDay)
return 1;
else
return 2;
}

回答2:

if (DateTime.Now.TimeOfDay >= Convert.ToDateTime("08:00").TimeOfDay && DateTime.Now.TimeOfDay < Convert.ToDateTime("19:59").TimeOfDay)
return 1
else
return 2