【问题标题】:Format Time from the json Result in angular2angular2中json结果的格式时间
【发布时间】:2017-12-04 07:10:45
【问题描述】:

我正在尝试根据json 结果格式化时间。这是我的代码

if (Object.keys(billNoData).length > 0) {
          for (var x in billNoData) {
               this.dayByBillNoExport.push({                                   
                     'Time': this.datePipe.transform(billNoData[x].BillTime, 'HH:mm'),                                    
                     })
               }
       }

我希望有时间以14:37. 的形式存储在数组中

但我得到以下错误

ERROR Error: InvalidPipeArgument: '14:37:04' for pipe 'DatePipe'
at invalidPipeArgumentError (invalid_pipe_argument_error.ts:1)
at DatePipe.transform (date_pipe.ts:91)
at SafeSubscriber.eval [as _next] (sales.component.ts:273)
at SafeSubscriber.__tryOrUnsub (Subscriber.ts:238)
at SafeSubscriber.next (Subscriber.ts:190)
at Subscriber._next (Subscriber.ts:135)
at Subscriber.next (Subscriber.ts:95)
at CatchSubscriber.Subscriber._next (Subscriber.ts:135)
at CatchSubscriber.Subscriber.next (Subscriber.ts:95)
at MapSubscriber._next (map.ts:80)

我也导入了DatePipe

import { DatePipe } from '@angular/common';

谁能帮帮我。

【问题讨论】:

    标签: angular2-routing angular2-template angular2-services


    【解决方案1】:

    您在转换方法中传递了错误的参数“HH:mm”。请参考https://angular.io/api/common/DatePipe链接。

    【讨论】:

    • 我是否需要通过“短时间”。我也试过了,但我得到了同样的错误。我应该在 transform 方法中传递什么?
    猜你喜欢
    • 1970-01-01
    • 2018-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多