angular2-moment
moment.js pipes for Angular
This module works with Angular 2.0 and above.
For the AngularJS version of this module, please see angular-moment.
Installation
npm install --save angular2-moment
If you use typescript 1.8, and typings, you may also need to install typings for moment.js:
typings install --save moment
For System.js users:
First you need to install moment:
npm install moment --save
Don't forget to update your systemjs.config.js:
packages: {
app: {
main: './main.js',
defaultExtension: 'js'
},
'moment': {
main: './moment.js',
defaultExtension: 'js'
},
'angular2-moment': {
main: './index.js',
defaultExtension: 'js'
}
}
Usage
Import MomentModule
into your app's modules:
;
This makes all the angular2-moment
pipes available for use in your app components.
Available pipes
amTimeAgo pipe
Takes an optional omitSuffix
argument that defaults to false
.
Prints Last updated: a few seconds ago
Prints Last updated: a few seconds
amCalendar pipe
Takes optional referenceTime
argument (defaults to now)
and formats
argument that could be output formats object or callback function.
See momentjs docs for details.
Prints Last updated: Today at 14:00
(default referenceTime is today by default)
Prints Last updated: Yesterday at 14:00
(referenceTime is tomorrow)
Prints Last updated: Same Day at 2:00 PM
amDateFormat pipe
Prints Last updated: January 24, 2016
amParse pipe
Parses a custom-formatted date into a moment object that can be used with the other pipes.
Prints Last updated: January 24, 2016
amLocal pipe
Converts UTC time to local time.
Prints Last updated 2016-01-24 12:34
amLocale pipe
To be used with amDateFormat pipe in order to change locale.
Prints Last updated: January 24th 2016, 2:23:45 pm
amFromUnix pipe
Prints Last updated: 01:46PM
amDuration pipe
Prints Uptime: 6 minutes
amDifference pipe
Prints Expiration: 1 day
amAdd and amSubtract pipes
Use these pipes to perform date arithmetics. See momentjs docs for details.
Prints Expiration: 2017-03-17 18:55
Prints Last updated: 2012-03-17 16:55
amFromUtc pipe
Parses the date as UTC and enables mode for subsequent moment operations (such as displaying the time in UTC). This can be combined with amLocal
to display a UTC date in local time.
Prints Last updated: 2017-01-01
amUtc pipe
Enables UTC mode for subsequent moment operations (such as displaying the time in UTC).
Prints Last updated: 2017-01-01
Complete Example
;;;;platformBrowserDynamic.bootstrapModuleAppModule;