Binding DateTime property of AngularJS model with format

I have a model with many datetime properties, I have a LastUpdatedTime property that I use for Concurrency and will not bind to any control. and this rendering of the client side datetime properties as / Date (1224043200000) /, when saved in the mvc controller, it does not recognize / Date (1224043200000) / as a valid format and does not accept the default date and does not perform a save operation. so any general solution after retrieving the model and before rendering, so that I can change the format for all datetime properties in the model.

+3


source to share


2 answers


You have to extract the fraction of milliseconds from "/ Date (1224043200000) /" (1224043200000) and convert it to a valid date format and associate it with the appropriate attribute in your model.



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

Run codeHide result


0


source


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

Use 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

0


source







All Articles