date format yyyy-MM-ddTHH:mm:ssZ

后端 未结 9 2225
走了就别回头了
走了就别回头了 2020-11-28 04:49

I assume this should be pretty simple, but could not get it :(. In this format Z is time zone.
T is long time pattern
How could I get a date in this format excep

相关标签:
9条回答
  • 2020-11-28 05:11

    In C# 6+ you can use string interpolation and make this more terse:

    $"{DateTime.UtcNow:s}Z"
    
    0 讨论(0)
  • 2020-11-28 05:14

    You could split things up, it would require more code but would work just the way you like it:

    DateTime year = DateTime.Now.Year;
    DateTime month = DateTime.Now.Month;
    DateTime day = DateTime.Now.Day;
    

    ect.

    finally:

    Console.WriteLine(year+month+day+etc.);
    

    This is a very bold way of handling it though...

    0 讨论(0)
  • 2020-11-28 05:18

    It works fine with Salesforce REST API query datetime formats

    DateTime now = DateTime.UtcNow;
    string startDate = now.AddDays(-5).ToString("yyyy-MM-ddTHH\\:mm\\:ssZ");   
    string endDate = now.ToString("yyyy-MM-ddTHH\\:mm\\:ssZ");  
    //REST service Query 
    string salesforceUrl= https://csxx.salesforce.com//services/data/v33.0/sobjects/Account/updated/?start=" + startDate + "&end=" + endDate;
    
    // https://csxx.salesforce.com/services/data/v33.0/sobjects/Account/updated/?start=2015-03-10T15:15:57Z&end=2015-03-15T15:15:57Z
    

    It returns the results from Salesforce without any issues.

    0 讨论(0)
提交回复
热议问题