ionic3使用moment.js
安装npm模块
$ npm install moment
例如在/home/home.ts文件里
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import * as moment from 'moment';
创建一个当前时间变量
export class HomePage {
public date: any;
constructor(public navCtrl: NavController) {
setInterval(()=>{
this.date = moment().format('YYYY-MM-DD HH:mm:ss');
}, 1000);
}
}
home/home.html文件处理
<ion-content padding>
time is {{ date }}
</ion-content>