My controller sends date data to the view using JSON. On the view I'm sending those data to a jQuery template to display. My problem is date, since I'm getting this value like
"/Date(1245398693390)/"
So I've tried with this solution but using FireBug I can see that an error is thrown at line
var value = new Date(parseInt(jsonDate.substr(6)));
with the error
jsonDate.substr is not a function
If it's important at all I'm trying to implement this using jQuery mobile.
Update
<script id="myDataTemplate" type="text/html">
<li>@Html.ActionLink("${GetDateString(Date)}", "Fetch", "Data")</li>
</script>
and this is js function injected in Layout view
<script>
function getDateString(jsonDate) {
if (jsonDate == undefined) {
return "";
}
var utcTime = parseInt(jsonDate.substr(6));
var date = new Date(utcTime);
var minutesOffset = date.getTimezoneOffset();
return date.addMinutes(minutesOffset).toString("M/d/yyyy h:mm tt");
}
</script>
Update 2 This is js function I originally used
function GetDate(jsonDate) {
var value = new Date(parseInt(jsonDate.substr(6))); //breaks
return value.getMonth() + 1 + "/" + value.getDate() + "/" + value.getFullYear();
}