本文整理汇总了C#中Raven.Imports.Newtonsoft.Json.JsonTextReader.ReadAsDateTime方法的典型用法代码示例。如果您正苦于以下问题:C# JsonTextReader.ReadAsDateTime方法的具体用法?C# JsonTextReader.ReadAsDateTime怎么用?C# JsonTextReader.ReadAsDateTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Raven.Imports.Newtonsoft.Json.JsonTextReader
的用法示例。
在下文中一共展示了JsonTextReader.ReadAsDateTime方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DateParseHandling
public void DateParseHandling()
{
string json = @"[""1970-01-01T00:00:00Z"",""\/Date(0)\/""]";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
reader.DateParseHandling = Json.DateParseHandling.DateTime;
Assert.IsTrue(reader.Read());
Assert.IsTrue(reader.Read());
Assert.AreEqual(new DateTime(DateTimeUtils.InitialJavaScriptDateTicks, DateTimeKind.Utc), reader.Value);
Assert.AreEqual(typeof(DateTime), reader.ValueType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(new DateTime(DateTimeUtils.InitialJavaScriptDateTicks, DateTimeKind.Utc), reader.Value);
Assert.AreEqual(typeof(DateTime), reader.ValueType);
Assert.IsTrue(reader.Read());
#if !NET20
reader = new JsonTextReader(new StringReader(json));
reader.DateParseHandling = Json.DateParseHandling.DateTimeOffset;
Assert.IsTrue(reader.Read());
Assert.IsTrue(reader.Read());
Assert.AreEqual(new DateTimeOffset(DateTimeUtils.InitialJavaScriptDateTicks, TimeSpan.Zero), reader.Value);
Assert.AreEqual(typeof(DateTimeOffset), reader.ValueType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(new DateTimeOffset(DateTimeUtils.InitialJavaScriptDateTicks, TimeSpan.Zero), reader.Value);
Assert.AreEqual(typeof(DateTimeOffset), reader.ValueType);
Assert.IsTrue(reader.Read());
#endif
reader = new JsonTextReader(new StringReader(json));
reader.DateParseHandling = Json.DateParseHandling.None;
Assert.IsTrue(reader.Read());
Assert.IsTrue(reader.Read());
Assert.AreEqual(@"1970-01-01T00:00:00Z", reader.Value);
Assert.AreEqual(typeof(string), reader.ValueType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(@"/Date(0)/", reader.Value);
Assert.AreEqual(typeof(string), reader.ValueType);
Assert.IsTrue(reader.Read());
#if !NET20
reader = new JsonTextReader(new StringReader(json));
reader.DateParseHandling = Json.DateParseHandling.DateTime;
Assert.IsTrue(reader.Read());
reader.ReadAsDateTimeOffset();
Assert.AreEqual(new DateTimeOffset(DateTimeUtils.InitialJavaScriptDateTicks, TimeSpan.Zero), reader.Value);
Assert.AreEqual(typeof(DateTimeOffset), reader.ValueType);
reader.ReadAsDateTimeOffset();
Assert.AreEqual(new DateTimeOffset(DateTimeUtils.InitialJavaScriptDateTicks, TimeSpan.Zero), reader.Value);
Assert.AreEqual(typeof(DateTimeOffset), reader.ValueType);
Assert.IsTrue(reader.Read());
reader = new JsonTextReader(new StringReader(json));
reader.DateParseHandling = Json.DateParseHandling.DateTimeOffset;
Assert.IsTrue(reader.Read());
reader.ReadAsDateTime();
Assert.AreEqual(new DateTime(DateTimeUtils.InitialJavaScriptDateTicks, DateTimeKind.Utc), reader.Value);
Assert.AreEqual(typeof(DateTime), reader.ValueType);
reader.ReadAsDateTime();
Assert.AreEqual(new DateTime(DateTimeUtils.InitialJavaScriptDateTicks, DateTimeKind.Utc), reader.Value);
Assert.AreEqual(typeof(DateTime), reader.ValueType);
Assert.IsTrue(reader.Read());
#endif
}