c# - 角日期类型
问题描述
从我的角度界面日期值来看是这样的。
Sat Dec 29 2018 08:42:06 GMT+0400 (Gulf Standard Time)
但是在从 api JSON 结果接收数据后看起来像这样。如何使它成为相同的类型?
2018-12-27T13:37:00.83
打字稿
export interface header{
vr_date : Date
}
ASP API 类
public class header
{
public Nullable<System.DateTime> vr_date { get; set; }
}
解决方案
您可以使用 Angular 的内置DatePipe
. 所以你需要做的就是:
在组件 TS 中:
import { DatePipe } from '@angular/common';
@Component({
// other stuff
providers:[DatePipe]
})
constructor(public datePipe : DatePipe){
}
要使用它:
var format = "yyyy-MM-dd HH:mm:ss"; // this could be `yyyy-MM-dd` or `MM/dd/yyyy`
this.datePipe.transform(your_date_variable, format);
编辑:
如果要将日期转换为 GMT,请使用your_date.toUTCString()
然后使用:
var isoDate = new Date('2018-12-27T13:37:00.83');
var UTCDate = isoDate.toUTCString();
返回:
Thu, 27 Dec 2018 08:07:00 GMT
推荐阅读
- server - Apache Ignite 服务器到客户端的连接问题
- scala - 如何将 java.util.HashSet[java.lang.Long] 转换为 Scala Set[Long]
- c# - 使用 C# 插值时如何处理变量中的空格?
- debugging - Salesforce 调试日志 VFRemoting 过滤
- powerbi - Power BI DAX 公式一起除法和减法
- sql-server - 在 SQL Server 2008 中处理插入/更新语句的最佳方法?
- javascript - 使步骤作为指导
- json - 在 JSON 中查找列表中项目的出现次数
- windows - 为什么批处理 %variable% 中传递的值未正确应用?
- magento2 - Magento 2 Custom shipping Carrier 模块