Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS: How to print out duration time with format?

I use below code to print the time duration:

{{(endTime - startTime) * 1000 | date: 'H:mm:ss'}}

But I get the time of GMT +8

AngularJS has any way to print out the non-convert duaration, Or I need to use this way to do this?

{{(endTime - startTime) % (60 * 60 * 24) / (60 * 60) | number: 0}}:
{{(endTime - startTime) % (60 * 60) / 60 | number: 0}}:
{{(endTime - startTime) % 60 | number: 0}}
like image 272
Chen-Tsu Lin Avatar asked Jan 29 '14 05:01

Chen-Tsu Lin


Video Answer


1 Answers

In AngularJS 1.3 and up, there is optional timezone argument in date filter. The doc says If the timezone is not specified, the timezone of the browser will be used.

https://code.angularjs.org/1.3.0/docs/api/ng/filter/date

Adding 'UTC' timezone will print the duration.

{{(endTime - startTime) | date: 'H:mm:ss': 'UTC'}}
like image 116
Aung Khaing Oo Avatar answered Sep 20 '22 19:09

Aung Khaing Oo