Filter which parses date (11/23/1996 12:23:42
) to timestamp.
For some reason, Angular's date
filter doesn't seem to be able to convert timestamp format M-d-Y h:i:s
properly. This library allows you to convert your date (string or a Date instance) to a timestamp.
Not sure if it works with versions Angular <=1.2
, but it should work fine (unless the Filter
API changed) with Angular >=1.2
.
angular-timestamp-filter
is available in [bower]
$ bower install angular-srph-timestamp-filter
While it is also possible to use a CDN (thanks to RawGit).
<!-- use this for examples or during development -->
<script src="https://rawgit.com/srph/angular-timestamp-filter/master/angular-timestamp-filter.js"></script>
<!-- or you could just forget about it and use this (recommended for production) -->
<script src="https://cdn.rawgit.com/srph/angular-timestamp-filter/master/angular-timestamp-filter.js"></script>
Include the script in your template (replace path/to/
with its proper path) after AngularJS.
<!-- make sure they are in proper order -->
<script src="path/to/angular.js"></script>
<!-- other scripts... -->
<script src="path/to/angular-timestamp-filter.js"></script>
Add in the library's module to your module's dependencies:
angular.module('your-app-name', [/** other deps */, 'srph.timestamp-filter']);
Through html binding (delimiters {{}}
)
{{ '11/23/1996' | timestamp }}
You can do the same thing with ng-bind
<span ng-bind="'11/23/1996' | timestamp"></span>
Or with $filter
MyController.$inject = ['$scope', '$filter'];
function MyController($scope, $filter) {
$scope.date = $filter('timestamp')('11/23/1996');
}
The most practical way to use this library is to integrate it with the date
filter by Angular. For instance,
{{ '11/23/1996 00:00:00' | timestamp | date: 'MMM d, yyyy' }}
<!-- should display Nov. 23, 1996 -->
* As of version v0.1.0
, angular-timestamp-filter
now harmonically works with Firefox Date.parse
issue with dashes.
I have no time as of now, but you can check if there are issues with Date.parse
.
See the Changelog file.
I'd suggest to submit an issue first before putting up a pull-request as this avoids closed pull-requests; no wasted work. Feel free to put up an issue or submit a pull-request!
Not obligatory, but don't forget to add tests!
Check the Building docs.
angular-timestamp-filter © 2015+, Kier Borromeo (srph). angular-timestamp-filter is released under the MIT license.
srph.github.io · GitHub @srph · Twitter @_srph