Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个连接到 wcf 服务以获取数据的移动应用程序。服务端的对象之一具有 TimeSpan DataMember。除了这个字段,一切都很好,因为它是一个字符串:
服务移动 04:00:00 --> "PT4H"
如何从 wcf 服务获取 TimeSpan?
提前致谢!
好的,我发现了问题。默认情况下,TimeSpan被序列化为
TimeSpan
XmlElementAttribute(DataType="duration")
这是一个类似“PT4H”的字符串。
要获得您必须使用XmlConvert.ToTimeSpan()的实际值,它将返回实际的时间跨度值。
XmlConvert.ToTimeSpan()