Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://jsfiddle.net/uZWQY/37/" rel="nofollow">http://jsfiddle.net/uZWQY/37/</a> has an example of a angular directive for 2 types of date formatting. One is the date formatter, the other is to cope with $scope elements that are formatted as a Microsoft Json Date: /Date(1369980188993)/</p> <p>The Date format from 'Epoch' is now fixed in Micorost <a href="http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx" rel="nofollow">.Net 4.5 MVC JavascriptSerializer</a>. The pain felt by many including <a href="http://www.hanselman.com/blog/OnTheNightmareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx" rel="nofollow">TheHansleMan</a> is now lessened by: How to swap out the serializer to JSON.NET on Henrik's blog <a href="http://blogs.msdn.com/b/henrikn/archive/2012/02/18/using-json-net-with-asp-net-web-api.aspx" rel="nofollow">http://blogs.msdn.com/b/henrikn/archive/2012/02/18/using-json-net-with-asp-net-web-api.aspx</a></p> <p>Angular Solution (with out "cheating" and reformatting the date as a string on the server):</p> <p>HTML</p> <p><code>&lt;input type="text" size="35" ng-model="testTime" jsondate='dd/MM/yyyy'&gt;</code></p> <p>Javascript:<code>myApp.directive('jsondate', function (dateFilter) { return { require:'ngModel', link:function (scope, elm, attrs, ctrl) { var dateFormat = 'dd/MM/yyyy'; ctrl.$formatters.unshift(function (modelValue) { var newDate = new Date(parseInt(modelValue.replace("/Date(", "").replace(")/", ""), 10)); ctrl.$setValidity('jsondate', true); return dateFilter(newDate, dateFormat); }); } }; });</code></p> <p>NOTE: will only work OUTSIDE a ng-repeat. You have to do the 'Long' Directive format for it to work : <a href="http://docs.angularjs.org/guide/directive" rel="nofollow">http://docs.angularjs.org/guide/directive</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload