Ionic | Working with moments.js
Inhaltsverzeichnis
Introduction
With moment.js, you can
Parse, validate, manipulate, and display dates and times in JavaScript.
With a npm-Module, you can integrate this functionality into your Ionic App
Preparation
Create your empty app
$ ionic start working-with-moments blank --no-git --no-link
Install npm Module
$ cd working-with-moments $ npm install moment + moment@2.20.1 added 1 package in 3.001s
Start Editor and serve your app
$ vscode . $ ionic serve
Add moments.js functionality
Change pages/home/home.ts
Add the moments.js reference to pages/home/home.ts
import { Component } from '@angular/core'; import { NavController } from 'ionic-angular'; import * as moment from 'moment';
Create a var for the current date/time
export class HomePage { public date: any; constructor(public navCtrl: NavController) { this.date = moment(); } }
Change pages/home/home.html
<ion-content padding> The current date/time is {{ date }} </ion-content>
Summary
A lot more examples could be found in my repository. Just create a starter app with this template and begin to play
$ ionic start app https://github.com/ionic4-toolbox/Working-with-moment.js
Leave a Reply