2

I have following values for my Subscription StartDate and EndDate in my database.

StartDate = 2017-05-12 16:13:39.007 
EndDate   = 2017-10-12 10:23:28.100

My API Controller.

public HttpResponseMessage GetSubscription()
{

 var license = _licenseService.GetLicense(curUser.Id);
 response = Util.Create(HttpStatusCode.OK, message: "Subscription Found", data: license);
}

This is how my response looks in postman.

{
"statusCode": 200,
"data": {
"licenses": [
  {
    "licenseId": 597,
    "startDate": "2017-05-12T16:13:39.007Z",
    "endDate": "2017-10-12T10:23:28.1Z" // notice 100 ms is trimmed to 1
   }
  ]}}

If you notice in the above response the number of characters in the date(s) are different.Because 00 part of the ms is trimmed

But this creates problem for my mobile clients because they format the date accordingly.

How do I make sure such trimming doesn't happen for any date whether the date has value like

2017-05-12 16:13:39.007  or 2017-05-12 16:13:39.000 

Thanks.

Kgn-web
  • 7,047
  • 24
  • 95
  • 161
  • what does the ending `Z` mean? – Lei Yang May 12 '17 at 11:29
  • Apparently your mobile clients do not *format* date. They just accept and display whatever string they receive as string. If they actually formatted the date, it would not matter for them because 1/10 is 100/1000. – GSerg May 12 '17 at 11:31
  • You can use [custom formatter](http://stackoverflow.com/q/18635599/1997232) for `DateTime` or another property to serialize/deserialize `DateTime` property as string, but the question is: does it really create a problem? `20.1` seconds = `20100` ms and not `20001` ms as you claim. – Sinatr May 12 '17 at 11:35
  • @GSerg, they do but they accept a string in the below format. var date = Date(fromString:timeString, format: .custom("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"), timeZone: .utc) – Kgn-web May 12 '17 at 11:35
  • @Sinatr, yes it is creating is problem. Please read my above comment to understand how – Kgn-web May 12 '17 at 11:38
  • @LeiYang, UTC Time Zone – Kgn-web May 12 '17 at 11:39

0 Answers0