1. 程式人生 > >angular4時間轉換,js保留兩位小數點(分值轉換),angular4前端管道保留兩位小數

angular4時間轉換,js保留兩位小數點(分值轉換),angular4前端管道保留兩位小數

一、 angular4時間轉換

1. 

var time1 = new Date().format("yyyy-MM-dd hh:mm:ss");

2.  在ts中注入datePipe管道,

import { DatePipe } from '@angular/common';         constructor( private datePipe: DatePipe
) {}

再module中providers中提供DatePipe

import { DatePipe } from '@angular/common';
@NgModule({ imports: [ CommonModule
, FormsModule ], declarations: [], providers:[ DatePipe, ]})export class TaskMonitoringModule { }

在ts中呼叫即可

this.datePipe.transform(new Date(), 'yyyy-MM-dd')

2.js保留兩位小數

var number=0.1256; number=(number*100).toFixed(2);

3. angular4(百分制)前端管道保留兩位小數

{{0.1415965*100 | number:"0.1-2"}}