ASP.Net Web API is returning JSON datetime without time

555 views Asked by At

I am facing a strange issue in ASP.Net Web API returning data which return records to display in tabular format, and that data also contains datetime. The problem is when I get data from client, the time part is removed and only date part is retrieved i.e. in "MM/dd/yyyy" format (even log in browser console), while debugging the code, I can see datetime in format "MM/dd/yyyy HH:mm:ss". I have tried every possibility but could not get it working.

Here is the json data during debug C# code:

{"Records": [
  {
    "ProviderName": "Loc 1",
    "FirstName": "A252",
    "LastName": "B252",
    "PhoneNumber": "8000121431",
    "EmailAddress": "[email protected]",
    "FormName": "Guest",
    "CreatedDate": "2020-10-01 08:50:00 AM",
    "Activate Alert Value": "Yes",
    "Are you experiencing cough?": "No",
    "Are you experiencing fever?": "Yes",
    "Are you sneezing?": "Yes",
    "Alert": "No"
  },
  {
    "ProviderName": "Loc 1",
    "FirstName": "A251",
    "LastName": "B251",
    "PhoneNumber": "8000121430",
    "EmailAddress": "[email protected]",
    "FormName": "Guest",
    "CreatedDate": "2020-10-01 08:29:00 AM",
    "Activate Alert Value": "Yes",
    "Are you experiencing cough?": "Yes",
    "Are you experiencing fever?": "Yes",
    "Are you sneezing?": "No",
    "Alert": "No"
  },
}

And here is the data which I log in browser console.

{"Records": [
    {
      "ProviderName": "Loc 1",
      "FirstName": "A252",
      "LastName": "B252",
      "PhoneNumber": "8000121431",
      "EmailAddress": "[email protected]",
      "FormName": "Guest",
      "CreatedDate": "10/1/2020",
      "Activate Alert Value": "Yes",
      "Are you experiencing cough?": "No",
      "Are you experiencing fever?": "Yes",
      "Are you sneezing?": "Yes",
      "Alert": "No",
      "$$hashKey": "uiGrid-000G"
    },
    {
      "ProviderName": "Loc 1",
      "FirstName": "A251",
      "LastName": "B251",
      "PhoneNumber": "8000121430",
      "EmailAddress": "[email protected]",
      "FormName": "Guest",
      "CreatedDate": "10/1/2020",
      "Activate Alert Value": "Yes",
      "Are you experiencing cough?": "Yes",
      "Are you experiencing fever?": "Yes",
      "Are you sneezing?": "No",
      "Alert": "No",
      "$$hashKey": "uiGrid-000I"
    },
}

Here is the code using NewtonSoft to convert data to Json Object

var json = Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(Newtonsoft.Json.JsonConvert.SerializeObject(report));
                return Ok(json);

The "json" variable contains exact the same 1st json data. It seems that when it returns data through OK(json) it manipulates the datetime.

Please refer to CreatedDate in json data for the current issue.

0

There are 0 answers