How to parse date time from json?
13,914
Use this in your javascript (while jsonDate = "\/Date(1369332000000)\/"
):
var date = new Date(parseInt(jsonDate.substr(6)));
var formattedDate = date.format("dd-MM-yyyy");
Source: How do I format a Microsoft JSON date?
Author by
Atish Dipongkor
Updated on August 21, 2022Comments
-
Atish Dipongkor over 1 year
I have a Action Method like this
public ActionResult TodayJson() { DateTime today = DateTime.Today; return Json(today,JsonRequestBehavior.AllowGet); }
that returns me the the following value
"\/Date(1369332000000)\/"
How can I parse it in actual date time by the jquery or java script. Format should be like this dd-mm-yyyy
-
Mike Christensen almost 11 yearsNote that solution wouldn't be time zone safe.
-
Adam Tal almost 11 years@MikeChristensen - stackoverflow.com/a/2316066/1203115 - look at the second comment (+35), it will work if timezone offset is specified.
-
Atish Dipongkor almost 11 yearsnow it gives "24-00-2013". it's not the actual value
-
Mike Christensen almost 11 yearsYes, however your date format is
"dd-mm-yyyy"
. -
Mike Christensen almost 11 years@AtishDipongkor - You probably want
dd-MM-yyyy
, lower casemm
is minute, not month. -
Adam Tal almost 11 yearsSorry had a mistake in the date.format string.
-
Atish Dipongkor almost 11 yearsthanks @AdamFridental. It's working now