我试图将2个日期时间参数传递到我的webget中,但是我想不出如何使它正常工作,我将向您展示我下面的代码,以及我得到的错误--也许现在有人是这样做的。
[WebGet]
public IQueryable<TestTable> GetCallersByDate(string beginDate, string eindDate)
{
testCDREntities context = this.CurrentDataSource;
DateTime startDt = DateTime.Parse(beginDate);
DateTime endDt = DateTime.Parse(eindDate);
var selectedOrders = from table in context.TestTables
where table.Created >= startDt && table.Created <= endDt
select table;
return selectedOrders;
}网址:
http://localhost:50088/WebService.svc/GetCallersByDate?beginDate=2016/03/23T20:22:30:14&eindDate=2016/03/2T20:13:11:03我希望有人能帮我?
发布于 2016-04-01 00:25:07
考虑到下面的数据,您应该使用DateTime.ParseExact而不是通常的DateTime.Parse
http://localhost:50088/WebService.svc/GetCallersByDate?beginDate=2016/03/23T20:22:30:14&eindDate=2016/03/2T20:13:11:03
我们可以看到日期字符串的格式是yyyy/MM/ddTHH:mm:ss和AFAIK,这种格式不是.NET的原生格式。
初学者=2016/03/23T20:22:30:14 eindDate=2016/03/2T20:13:11:03
string dateFormat = "yyyy/MM/ddTHH:mm:ss";
DateTime startDt = DateTime.ParseExact(beginDate, dateFormat, CultureInfo.InvariantCulture);
DateTime endDt = DateTime.Parse(eindDate, dateFormat, CultureInfo.InvariantCulture);https://stackoverflow.com/questions/36345701
复制相似问题