Passing DateTimeOffset as WebAPI query string

前端 未结 8 597
感动是毒
感动是毒 2020-12-11 15:49

I\'ve got a WebAPI action that looks like so:

[Route(\"api/values/{id}\")]
public async Task Delete(string id, DateTimeOffset date         


        
8条回答
  •  無奈伤痛
    2020-12-11 16:33

    Here is the easiest way for those who are looking for some kind of sync between client and server using datetime. I implemented that for mobile application. It is independent from the culture of the client. because my mobile app supports multiple cultures and it is boring to use formatting between those cultures. thanks that .net has a perfect functions called ToFileTime and FromFileTime

    Server Controller Action:

    [HttpGet("PullAsync")]
    public async Task PullSync(long? since = null, int? page = null, int? count = null)
    {
        if (since.HasValue) 
            DateTimeOffset date = DateTimeOffset.FromFileTime(since.Value);    
    }
    

    Client Side

    DateTimeOffset dateTime = DateTime.Now.ToFileTime();
    var url= $"/PullAsync?since={datetime}&page={pageno}&count=10";
    

提交回复
热议问题