Finally, I examined this problem as shown below (C #)
[DataMember] public string Date { get; set; } [IgnoreDataMember] public DateTime? DateForInternalUse { get; set; } [OnSerializing] public void OnSerializing(StreamingContext context) { Date = (DateForInternalUse != null) ? ((DateTime)DateForInternalUse).ToString(DateTimeFormatForSerialization) : null; } [OnDeserialized] public void OnDeserialized(StreamingContext context) { try { DateForInternalUse = !String.IsNullOrEmpty(Date) ? DateTime.ParseExact(Date, DateTimeFormats, null, DateTimeStyles.None) : (DateTime?)null; } catch (FormatException) { DateForInternalUse = null; } }
In this case, we can specify the formats that we want to support, which I saved in web.config
<add key="DateTimePattern" value="yyyy-MM-dd,yyyy-MM-dd hh:mm:ss zzz,yyyy-MM-dd hh:mm:ss" />
Let me know for further clarification.
source share