當(dāng)我使用來反序列化時(shí)間字符串時(shí)XmlSerializer.Deserialize,我希望它考慮到我當(dāng)?shù)氐臅r(shí)區(qū),以便采用以下格式的時(shí)間字符串00:00:00.0000000+01:00被解析為00:00,因?yàn)槲宜诘臅r(shí)區(qū)為GMT + 1。我說錯(cuò)了嗎?這是我正在測試xml反序列化的代碼:using System;using System.IO;using System.Xml.Serialization;using Microsoft.VisualStudio.TestTools.UnitTesting;namespace Testing{ [TestClass] public class FooTest { [TestMethod] public void Test() { var serializer = new XmlSerializer(typeof(Foo), new XmlRootAttribute("Foo")); var xml = "<Foo><TheTime>00:00:00.0000000+01:00</TheTime></Foo>"; var stream = new MemoryStream(); var writer = new StreamWriter(stream); writer.Write(xml); writer.Flush(); stream.Position = 0; var f = (Foo) serializer.Deserialize(stream); Assert.AreEqual("00:00", f.TheTime.ToShortTimeString()); // actual: 01:00 } [Serializable] public class Foo { [XmlElement(DataType = "time")] public DateTime TheTime { get; set; } } }}
- 1 回答
- 0 關(guān)注
- 322 瀏覽
添加回答
舉報(bào)
0/150
提交
取消