Change default date serialization in WCF

前端 未结 5 769
-上瘾入骨i
-上瘾入骨i 2020-12-03 07:39

Is there anyway to change the default JSON serialization/deserialization of DateTime in WCF?

Currently, DateTime are serialized into the /Date(1372252162657+0

5条回答
  •  盖世英雄少女心
    2020-12-03 08:23

    This does not solve your issue of timezones, but I'll post it here for others who are battling it out with WCF, ticks and DateTime.

    If you don't want ticks, but human-readable time format, you can do it by introducing an additional string property. Then it's a matter of fiddling with the DateTime before turning the value into a string.

        [IgnoreDataMember]    // Ignore the original tick date.
        public DateTime LastReminderDate { get { return _lastReminderDate; } set { _lastReminderDate = value; } }
        [DataMember]          // Make sure you have a public or private setter!
        public string LastReminderDateText { get { return _lastReminderDate.ToString(); } set { _lastReminderDate = DateTime.Parse(value); } }
    

提交回复
热议问题