看一下下面的示例代码,我希望输出为WCF日期格式"/date(1237951967000)/"或时区变体。
class Program
{
public class Test
{
public DateTime Date { get; set; }
}
static void Main(string[] args)
{
var test = new Test
{
Date = DateTime.Now
};
var json = JsonConvert.SerializeObject(test);
Console.WriteLine(json);
}
}
输出如下:
{"Date":"2013-05-09T11:17:38.7990259-07:00"}
如何调整上述代码以获得所需的格式?
{"Date":"/Date(1237951967000)/"}
var settings = new JsonSerializerSettings() {DateFormatHandling= DateFormatHandling.MicrosoftDateFormat};
var json = JsonConvert.SerializeObject(test, settings);