Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将当前时间与WPF中的lambda表达式进行比较_C#_Wpf_Timespan - Fatal编程技术网

C# 将当前时间与WPF中的lambda表达式进行比较

C# 将当前时间与WPF中的lambda表达式进行比较,c#,wpf,timespan,C#,Wpf,Timespan,我想使用lambda表达式比较当前的DateTime.Now和从数据库检索到的时间(time) 我试试这个: string time = DateTime.Now.Hour.ToString("00") + DateTime.Now.Minute.ToString("00") + DateTime.Now.Second.ToString("00"); TimeSpan _currentTime = TimeSpan.ParseExact(time, "HHmmss", CultureInfo.I

我想使用lambda表达式比较当前的DateTime.Now和从数据库检索到的时间(time)

我试试这个:

string time = DateTime.Now.Hour.ToString("00") + DateTime.Now.Minute.ToString("00") + DateTime.Now.Second.ToString("00");
TimeSpan _currentTime = TimeSpan.ParseExact(time, "HHmmss", CultureInfo.InvariantCulture);

IQueryable<user> Query = _context.user.Where(s => s.userShifts.Any(s2 => s2.DayOfWeekId == _todayNumber && _currentTime >= s2.TimeFrom && _currentTime <= s2.TimeTo));
string time=DateTime.Now.Hour.ToString(“00”)+DateTime.Now.Minute.ToString(“00”)+DateTime.Now.Second.ToString(“00”);
TimeSpan _currentTime=TimeSpan.ParseExact(时间,“HHmmss”,CultureInfo.InvariantCulture);

IQueryable Query=\u context.user.Where(s=>s.userShifts.Any(s2=>s2.DayOfWeekId==\u todayNumber&&&u currentTime>=s2.TimeFrom&&u currentTimeOk.。正确的格式是:

TimeSpan _currentTime = TimeSpan.ParseExact(time, "hh':'mm':'ss", null);

希望对您有所帮助。

使用TimeOfDay代替parseExact

var _currentTime= DateTime.Now.TimeOfDay

该代码无法编译:首先,第一条语句有两个错误。请提供一个实际的。我更新了示例为什么要费劲解析?为什么不直接执行var\u currentTIme=DateTime.Now.TimeOfDayRight,谢谢Danny的帮助。请注意,如果第二行是引发异常的地方,您应该我知道这与WPF或lambda表达式无关。请在提问之前认真进行诊断。谢谢Danny,这是我想要的正确方法。