I need to bring javascript timestamp to server in datetime format. My javascript object contains a property with datetimstamp
ex : {"fromDate" : "new Date(1427826600000)"}
But the model on the server side has fromDate
as DateTime
. I need to deserialize it to DateTime on server side as I'm using different cultures.
below is the code.
Ajax Call
$.ajax({
type: "POST",
url: "Report/Update",
dataType: "json",
contentType: 'application/json',
data: JSON.stringify(model),
Model
public class Report
{
[JsonConverter(typeof (JavaScriptDateTimeConverter))]
public DateTime FromDate { get; set; }
[JsonConverter(typeof (JavaScriptDateTimeConverter))]
public DateTime ToDate { get; set; }
}
Controller
[HttpPost]
public JsonResult UpdateReport(Report data)
{
...
}
I'm unable to do this can you help me out?
Provided that
aMs
contains JS date, use this code to convert it to C# DateTime: