首页 > 解决方案 > 通过json发送和接收时的日期时间问题

问题描述

我在从角度“Thu Jan 10 2019 00:00:00 GMT+0400 (Gulf Standard Time)”中选择 DateTime 选择器时得到这个日期和时间,我系统中的实际日期时间是 2019 年 1 月 10 日 9.51

在 asp.net api 中接收数据时,我得到了这样的日期。{09/01/2019 晚上 8:00:00}

有角度的。

    export interface sample{
        vr_date: Date
    }

`this.adapter.setLocale('en-GB');` // i use this to get date format in dd/mm/yyyy format

ASP API

public class sample
{

        public Nullable<System.DateTime> vr_date{ get; set; }
}

标签: javascriptasp.netangularjsjson

解决方案


在转换为 JSON 之前将日期转换为字符串。

利用-

var date=dateObject.toLocaleDateString();

然后通过 JSON 发送日期。


推荐阅读