0
 JavaScriptSerializer js = new JavaScriptSerializer();
 var result = js.Serialize(data);

This is my model:

 public class EmployeeDetailsDTO : IEmployeeDetailsDTO
 {
    public int EmployeeId { get; set; }
    public string EmployeeName { get; set; }
    public Datetime date{get;set;}
 }

I Passed this serialized object into webapi from an MVC application through the body of the request.But in my webapi controller the date become one less(11-02- 2018 is changed into 10-02-2018).

but when i used this code the problem is solved.Did anybody know what is happening?

 var data = JsonConvert.SerializeObject(data);

webapi is deserializing the data for me.so explicitly writing (.ToLocalTime();) is not possible in this case.

Thaks
  • 640
  • 6
  • 14
  • More information. For example, what is the DateTime's `Kind` value in C#? What is the date value and timezone in C#? – ProgrammingLlama Jun 04 '18 at 07:25
  • Probably a time zone issue. Make sure that the date string in the JSON uses a format that is unambiguous, for example the "round-trip" format. See [How to: Round-trip Date and Time Values](https://learn.microsoft.com/en-us/dotnet/standard/base-types/how-to-round-trip-date-and-time-values). – Georg Patscheider Jun 04 '18 at 07:26
  • 1
    why this issue is not in "JsonConvert.SerializeObject" ? – Thaks Jun 04 '18 at 07:52
  • JavaScriptSerializer by default seems to serialize to "Date(unixEpochValue)". JSON.Net serializes to a roundtrip format with timezone. Is this the same behaviour you see? – ProgrammingLlama Jun 04 '18 at 08:06
  • 1
    Yes.john is correct.so we can only use json.net for passing from mvc to webapi ? – Thaks Jun 04 '18 at 08:35

0 Answers0