在C#中解析Javascript日期的最简单的方法? [英] Easiest way to parse a Javascript date in C#?
本文介绍了在C#中解析Javascript日期的最简单的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我看到JSON.NET有一个DateTime转换器:
I see that JSON.NET has a DateTime converter:
string javascriptJson = JsonConvert.DeserializeObject(entry, new JavaScriptDateTimeConverter());
但是我没有JSON对象,我只需要一个字符串:
However I don't have a JSON object, I simply have a string:
/Date(1276146000000-0500)/
我可以创建一个对象,添加日期,然后解析它,但这似乎很常见,应该有一种方法来做到这一点。有没有什么东西?
I could create an object, add the date, then parse it, but this seems common enough that there should be a way to do this in a single line. Is there anything out there?
推荐答案
需要在日期字符串周围的引号。另外,返回的值是一个 DateTime
,而不是 string
。
The quotes around the date string are required. Also, the returned value is a DateTime
, not a string
.
DateTime date =
JsonConvert.DeserializeObject<DateTime>("\"/Date(1276146000000-0500)/\"");
这篇关于在C#中解析Javascript日期的最简单的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文