2017-11-22 12 views

答えて

0

私はあなたの要件とAngular2-momentを使用しました。このプラグインはパイプで構築されており、TSファイルでパイプを使用しようとしました。

Working demo

私はそれがまっすぐ進むの答えだかどうかわからないが、それはあなたの検索であなたを助けるかもしれません。

TSファイル

import { Component } from '@angular/core'; 
import { DateFormatPipe,DifferencePipe } from 'angular2-moment'; 

@Component({ 
    selector: 'my-app', 
    templateUrl: './app.component.html', 
    styleUrls: [ './app.component.css' ] 
}) 
export class AppComponent { 
    name = 'Angular 5'; 
    startTime : any; 
    endTime : any 
    diff : any; 

    constructor(){ 

    this.startTime=new Date().setHours(9,30); 
    this.endTime=new Date().setHours(17,50); 
    this.diff=(new DifferencePipe()).transform(this.endTime, this.startTime, 'Hours', true); 

    } 
} 

HTMLファイル

<hello name="{{ name }}"></hello> 
<p> 
    Start editing to see some magic happen :) 
</p> 

{{startTime}} : {{endTime}} : {{diff}} 
+0

split( ':')を使用して時間と分を取得します。 parseIntを使用して整数を取得し、時間に60を掛けて減算します。 %演算子を使用して分結果を取得し、Math.floorを使用して最終時間を取得します – Eliseo

0

問題は、コードの下に使用して解決されました:

this.daySettingsForm.totalPresence = moment.duration(
     this.daySettingsForm.departure.diff(this.daySettingsForm.arrival) 
    ).format(

TimeFormat.SHORT)。