Angular 角度5的时间戳
我正在处理一个使用Angular 5的项目,我正在使用Firebase。实际上,我以前使用过firebase:“^4.12.1”,它对我来说运行正常。现在项目的主题改变了,因为它面临许多问题,最后我不得不改变firebase的版本,所有问题都已解决,但面临时间戳问题。 下面是我的代码 .htmlAngular 角度5的时间戳,angular,angular-material,angular5,angular2-forms,Angular,Angular Material,Angular5,Angular2 Forms,我正在处理一个使用Angular 5的项目,我正在使用Firebase。实际上,我以前使用过firebase:“^4.12.1”,它对我来说运行正常。现在项目的主题改变了,因为它面临许多问题,最后我不得不改变firebase的版本,所有问题都已解决,但面临时间戳问题。 下面是我的代码 .html 开始日期 {{item.itemCategoryRows.startdate}日期:'dd/MM/yyyy'} 结束日期 {{item.itemCategoryRows.enddate}日期:'med
开始日期
{{item.itemCategoryRows.startdate}日期:'dd/MM/yyyy'}
结束日期
{{item.itemCategoryRows.enddate}日期:'mediumDate'}
您可以使用此{{item.itemCategoryRows.startdate*1000 | date:'dd/MM/yyyy'}}
并在时间戳中乘以1000
我已经在上创建了一个演示
开始日期
{{item.itemCategoryRows.startdate*1000 |日期:'dd/MM/yyyy'}
结束日期
{{item.itemCategoryRows.enddate*1000 |日期:'mediumDate'}
您可以使用此{{item.itemCategoryRows.startdate*1000 | date:'dd/MM/yyyy'}}
并在时间戳中乘以1000
我已经在上创建了一个演示
开始日期
{{item.itemCategoryRows.startdate*1000 |日期:'dd/MM/yyyy'}
结束日期
{{item.itemCategoryRows.enddate*1000 |日期:'mediumDate'}
这是因为Firebase JavaScript SDK中有一个突破性的更改,其中日期保存在数据库中并作为对象返回
在类中,有一个方法可以将对象转换为本机JavaScriptDate
开始日期
{{item.itemCategoryRows.startdate.toDate()|日期:'dd/MM/yyyy'}
结束日期
{{item.itemCategoryRows.enddate.toDate()|日期:'mediumDate'}}
这是因为Firebase JavaScript SDK中有一个突破性的更改,其中日期保存在数据库中并作为对象返回
在类中,有一个方法可以将对象转换为本机JavaScriptDate
开始日期
{{item.itemCategoryRows.startdate.toDate()|日期:'dd/MM/yyyy'}
结束日期
{{item.itemCategoryRows.enddate.toDate()|日期:'mediumDate'}}
您能检查一下您获取日期的格式吗?chrome(浏览器)控制台中显示了什么错误?item.itemCategoryRows.startdate的数据是什么?@PiniCheyni单击查看详细信息时控制台中出现了错误错误:InvalidPipeArgument:'时间戳(秒=1531681200,纳秒=0)'用于位于的管道'DatePipe'invalidPipeArgumentError@KrishnaRathore我使用的是反应式表单itemCategoryRows是一个数组,items是从firebase startdate获取数据后存储数据的另一个数组,formControlName是filed@Naeem我有帖子的答案。你能检查一下你是用哪种格式得到日期的吗?chrome(浏览器)显示了什么错误控制台?item.itemCategoryRows.startdate的数据是什么?这是单击查看详细信息时控制台中的错误错误错误:InvalidPipeArgument:'时间戳(秒=1531681200,纳秒=0)'用于位于的管道'DatePipe'invalidPipeArgumentError@KrishnaRathore我使用的是反应式表单itemCategoryRows是一个数组,items是从firebase startdate获取数据后存储数据的另一个数组,formControlName是filed@Naeem我已使用您的代码从控制台中删除了post应答。时间戳错误,但无法正常工作。日期未显示在网格中。我将在Stackblitz上创建演示我已在Stackblitz
上创建演示-使用您的代码从控制台中删除了时间戳错误,但无法正常工作。日期未显示在网格中。我将在Stackblitz上创建演示我已在Stackblitz
-
<ng-container matColumnDef="startdate">
<mat-header-cell *matHeaderCellDef mat-sort-header><b>Start Date</b> </mat-header-cell>
<mat-cell *matCellDef="let item"> {{item.itemCategoryRows.startdate | date: 'dd/MM/yyyy'}} </mat-cell>
</ng-container>
<ng-container matColumnDef="enddate">
<mat-header-cell *matHeaderCellDef mat-sort-header><b>End Date </b> </mat-header-cell>
<mat-cell *matCellDef="let item"> {{item.itemCategoryRows.enddate | date:'mediumDate'}} </mat-cell>
</ng-container>
<ng-container matColumnDef="startdate">
<mat-header-cell *matHeaderCellDef mat-sort-header>
<b>Start Date</b>
</mat-header-cell>
<mat-cell *matCellDef="let item"> {{item.itemCategoryRows.startdate * 1000 | date: 'dd/MM/yyyy'}} </mat-cell>
</ng-container>
<ng-container matColumnDef="enddate">
<mat-header-cell *matHeaderCellDef mat-sort-header>
<b>End Date </b>
</mat-header-cell>
<mat-cell *matCellDef="let item"> {{item.itemCategoryRows.enddate * 1000 | date:'mediumDate'}} </mat-cell>
</ng-container>