为什么时区会附加在DateTime的属性中

时间:2017-04-03 15:51:45

标签: c# json datetime asp.net-web-api

以下是我的DTO。

public class CustomerTO
{
  public int Id { get; set;}
  public DateTime? RDate {get;set;}
  public DateTime? LDate {get; set;}     

}

当我在数据库中检查RDate&的相应列的值时LDate如下: -

RDate = 2017-04-03 21:09:24.273
LDate = 2017-04-03 21:09:24.577

我的行动。

public string Get()
{
   var customers = dal.GetRecords();
   //if I hover the customers object & see the RDate or LDate value it is as desired.

var strJson= JsonConvert.SerializeObject(customers);
//but here the value of RDate/LDate has Time zone appended.
}

strJson包含RDate& LDate值如下。

RDate = 2017-04-03T21:09:24.5768697+05:30
LDate = 2017-04-03T21:09:24.5618688+05:30 // why +5:30 timezone is getting appended.

如何解决这个问题?

任何帮助/建议都非常感谢。

1 个答案:

答案 0 :(得分:0)

尝试将DateTimeZoneHandling的{​​{1}}属性设置为JsonSerializerSettings

Unspecified