我显示的秒数从3600减少到0.
<div class="time-box" *ngIf="p.value.playerTimer > 0">{{ p.value.playerTimer }}</div>
我想将秒数格式化为分钟:秒
我希望能够使用DatePipe – https://angular.io/api/common/DatePipe
<div class="time-box" *ngIf="p.value.playerTimer > 0">{{ p.value.playerTimer | date:'mmss' }}</div>
但这不起作用,因为它期望p.value.playerTimer是一个日期对象或自纪元以来的秒数.
还有另一种方法来实现这一目标吗?
你必须自己编写管道.像这样的东西.但请注意,它未经测试,并未考虑可能收到的任何奇怪输入.它也没有任何前导零,但是,嘿,现在你还有事要做:
@Pipe({ name: 'minuteSeconds' }) export class MinuteSecondsPipe implements PipeTransform { transform(value: number): string { const minutes: number = Math.floor(value / 60); return minutes + ':' + (value - minutes * 60); } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。