Does anyone know how to parse a json timespan object? I would like to return the UTC time frame to my view and then convert it to local client time, but I did not find any references to this.
I am using mvc, so I have this model:
public class TimeSpanModel
{
public TimeSpan StartTime { get; set; }
public TimeSpanModel()
{
this.StartTime = DateTime.UtcNow.TimeOfDay;
}
}
and in my controller, I return this model to my view as follows:
public ActionResult GetTimeSpanInfo()
{
TimeSpanModel tsm= new TimeSpanModel ();
return Json(tsm);
}
I make such a call from a view:
$.ajax({
type: 'POST',
url: '@Url.Content("~/Controller/GetTimeSpanInfo")',
success: function (data) {
alert(data.StartTime);
var dt = new Date(data.StartTime);
alert(dt.toString());
}
});
but in the first warning window I see only this: [object Object] so I tried to convert the timepan to Date, but in the second warning field I get an invalid date.
, , , "" , , ?
, TimeSpans datetime?
.
P.S. UTCnow, , UTC db - (0). , , - , , , .