0

I have a JSON string. When I send the string from my view to my controller via the POST method, one of the properties of this JSON, which is a datetime, is mapped in the format "dd/mm/yyyy". But when I send the same JSON string by the GET method, the same property is mapped in the format "mm/dd/yyyy", leaving the property with NULL for dates with days greater than 12. How to fix this problem? Can this be a Visual Studio problem? I'm using the Brazilian date format.

  • Which library are you using to serialize your object in the json format? Can you share some code? – Massimiliano Kraus May 08 '17 at 20:11
  • If you are using json.net, have a look at this: https://stackoverflow.com/questions/18635599/specifying-a-custom-datetime-format-when-serializing-with-json-net – user1845593 May 08 '17 at 20:12

2 Answers2

0

The response is always in format specified by RFC 7231. See for example this link.

Community
  • 1
  • 1
LSA
  • 404
  • 7
  • 11
0

you need to Specific Culture on the get request. since the browser use different culture than your sever , they should match,

  DateTime dt = DateTime.Now;
  // Sets the CurrentCulture property to U.S. English or whatever your browser using .
  Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
  // Displays dt, formatted using the ShortDatePattern
  // and the CurrentThread.CurrentCulture.
  Console.WriteLine(dt.ToString("d"));

for more check this : https://msdn.microsoft.com/en-us/library/5hh873ya(v=vs.90).aspx

H. Rashid
  • 176
  • 13