Skip to content Skip to sidebar Skip to footer

Parsing The C# Datetime To Javascript Datetime

I know that my question is similar to others but I didn't found any solution to my problem. I have a C# DateTime property public DateTime MyDate { get;set;} When I use an ajax to

Solution 1:

new Date(object.MyDate); should work.

EDIT: var date = new Date(parseInt(object.MyDate.substr(6)));

I've also seen this method:

var milli = "/Date(1245398693390)/".replace(/\/Date\((-?\d+)\)\//, '$1');
var d = newDate(parseInt(milli));

Solution 2:

I'm using .Net Core 2.0. & MySQL 5.7

In my current development, I'm assigning the returned value directly into the DOM object like this:

DOMControl.value = response.CreatedOn.toString().split(".")[0];

I'm returning a JsonResult of the resulting object, the resulting JSON arrives with the date value as follows:

{
  ...
  createdOn : "2017-11-28T00:43:29.0472483Z"
  ...
}

I hope this help to somebody.

Post a Comment for "Parsing The C# Datetime To Javascript Datetime"