我正在尝试使用 Newtonsoft.Json.JsonConvert 反序列化/序列化时间跨度,但是当发送 JSON 时,它被设置为 00:00:00。
这甚至可以做到吗?
最佳答案
我尝试了#Jessycormier 的方法,但它对我不起作用。 我运行 DataContractJsonSerializer 以查看它会生成什么,我发现它给了我一个看起来更像这样的值。
{"PassedTimeSpan":"P1DT2H3M4S"}
上面显示的值是 1 天 2 小时 3 分 4 秒。
所以看起来格式是:
[-]P[{days}D][T[{hours}H][{min}M][{sec}S]]
地点:
- Indicates negative timespan, omitted for positive values
P must be the first character (unless negative time value)
T must precede the time portion of the timespan.
[] = optional part that may be omitted if 0.
关于c# - 使用 JSON 序列化/反序列化 TimeSpan,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3232701/