我在使用 LINQ 查询时遇到问题 - 我正在使用它来选择一些飞行时间数据:
new XElement("Data",
from data in table
select new XElement("data", new XAttribute("data","data"),
new XElement("scheduledGateTime", data[1]),
new XElement("destinationCity", data[2]),
new XElement("flightNumber", data[3]),
new XElement("status", data[4]),
new XElement("terminal", data[4])
)
)
我在过滤时遇到问题,在带来所有数据的那一刻,但我需要它只选择当“scheduledGateTime”在今天的当前时间之后。
比如gate时间是09:05,现在是13:10,我不想选这个..但是如果比赛时间是13:11,应该选。
我没有经常使用 LINQ,不知道该怎么做,有人可以帮忙吗?
谢谢
最佳答案
尝试这样的事情:
new XElement("Data",
from data in table
where DateTime.ParseExact(data[1], "dd/MM/yy HH:mm:ss", CultureInfo.CurrentCulture) > DateTime.Now
select new XElement("data", new XAttribute("data","data"),
new XElement("scheduledGateTime", data[1]),
new XElement("destinationCity", data[2]),
new XElement("flightNumber", data[3]),
new XElement("status", data[4]),
new XElement("terminal", data[4])
)
您可能需要调整 DateTime
格式,我假设为“dd/MM/yy HH:mm:ss”。
关于c# - LINQ 只选择今天当前时间之后的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32396757/