Skip to content

📆 AngularJS filter which converts date to timestamp

Notifications You must be signed in to change notification settings

Katsivelisp/angular-timestamp-filter

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

angular-timestamp-filter

Build Status Bower version MIT license

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.

Getting Started

Requirements

Not sure if it works with versions Angular <=1.2, but it should work fine (unless the Filter API changed) with Angular >=1.2.

Installation

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']);

Usage

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 -->

Compatibility

* 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.

Changelog

See the Changelog file.

Contribution

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!

Building

Check the Building docs.

Acknowledgement

angular-timestamp-filter © 2015+, Kier Borromeo (srph). angular-timestamp-filter is released under the MIT license.

srph.github.io  ·  GitHub @srph  ·  Twitter @_srph

About

📆 AngularJS filter which converts date to timestamp

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%