2017-01-04 30 views
0

我試圖在我的Nativescript + Angular 2移動應用程序上添加DatePipe。它正在Android模擬器上工作,但在ios模擬器上出現錯誤。Angular2 DatePipe未在ios中工作

Error: file:///app/tns_modules/@angular/core/bundles/core.umd.js:9427:77: JS ERROR Error: Error in pages/home/home.component.html:86:29 caused by: Invalid argument '2016-11-15T10:51:07+0300' for pipe 'DatePipe'

我的代碼:<Label col="1" [text]="item.datetime | date:'yMMMd'"></Label>

請幫我解決這個問題。

回答

2

documentationDatePipe可用於像date_expression | date[:format]其中expression爲Date對象或數字(因爲UTC毫秒爲單位)或ISO字符串,以便確保您的item.datetime值將日期對象或數毫秒。

+0

感謝@ ranakrunal9,我已經加入Momentjs,現在它的工作的罰款。 – ramya0072

1
<Label class="EventTime" col="0" row="0" [text]="item.StartDate | date:'jm'"></Label> 

按照Doc

  1. '媒介':等同於 'yMMMdjms'(如2010年9月3日,下午12時05分08秒 爲EN-US)
  2. '短' :相當於'yMdjm'(eg 9/3/2010,12:05 PM for en-US)
  3. 'fullDate':相當於'yMMMMEEEEd'(例如2010年9月3日星期五, 2010 for en-US)
  4. 'longDate':相當於'yMMMMd'(例如Septem 'mediumDate':相當於'yMMMd'(例如,2010年3月, en-US)
  5. 'mediumDate' 2010年9月3日,爲en-US)
  6. 'shortDate':相當於'yMd'(eg 9/3/2010 for en-US)
  7. 'mediumTime':相當於'jms'(例如12:05 :08時爲EN-US)
  8. '短時':等同於 'JM'(例如12:05 PM爲EN-US)