3

I have a model with many datetime properties, in this i have LastUpdatedTime property which i am using for Concurrency functionality and will not be binding to any control in view. and this datetime properties rendering in client side as /Date(1224043200000)/, while saving in mvc controller, it is not recognizing /Date(1224043200000)/ as valid format and taking default date and failing the save operation. so any common solution after fetching the model and before rendering in view, so that i can change the format for all datetime properties in the model.

user720149
  • 61
  • 1
  • 4
  • Already answered here : http://stackoverflow.com/a/726869/1565402 – lbrahim Jul 29 '15 at 09:38
  • Thanks Ibrahim, i want angularjs method where we can convert all datetime properties in a model after fetching the model and before rendering it to view. i am not binding one Datetime property to any control in view, without binding the property i want to change the format of that property before sending to save. – user720149 Jul 30 '15 at 05:22
  • check out my answer below.! **without binding the property** by this what you mean! Let me know for further help – Aravind Jan 01 '17 at 10:43
  • Possible duplicate of [ASP.NET MVC JsonResult Date Format](http://stackoverflow.com/questions/726334/asp-net-mvc-jsonresult-date-format) – Claies Jan 02 '17 at 02:09

2 Answers2

0

You should extract the milliseconds part from "/Date(1224043200000)/" (1224043200000) and Convert it into valid date format and bind it into the relevant attribute of your model.

var datetimeInMilliseconds = parseInt("/Date(1224043200000)/".match(/\(([^)]+)\)/)[1]);
var convertedDateTime = new Date(datetimeInMilliseconds);
ArrayName.AttributeName = convertedDateTime ;
0

Assuming that the date value you have in your controller as var /Date(1224043200000)/

Use the below code

HTML

<body ng-controller="MainCtrl">
    <p>Hello ASP DATE ISSUE </p>
    {{dateValue.slice(6,19) | date}}
</body>

JS

var app = angular.module('aspDateApp', []);
app.controller('MainCtrl', funscope) {
  $scope.name = 'ASP DATE ISSUE';
  $scope.dateValue='/Date(1224043200000)/';
});

LIVE DEMO

Aravind
  • 40,391
  • 16
  • 91
  • 110