0

Webget に 2 つの datetime パラメータを渡そうとしましたが、正しく動作させる方法がわかりません。以下にコードを示します。

[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; 
}

URL :

http://localhost:50088/WebService.svc/GetCallersByDate?beginDate=2016/03/23T20:22:30:14&eindDate=2016/03/2T20:13:11:03

誰かが私を助けてくれることを願っていますか?

4

1 に答える 1

0

以下のデータを考えると、通常の DateTime.Parse の代わりに DateTime.ParseExact を使用する必要があります。

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 であり、この形式は .NET 固有のものではないことがわかります。

beginDate=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);
于 2016-04-01T00:25:07.113 に答える