日期时间力毫秒

问题描述:

我有一个WCF服务,返回数据为JSON。我有一个问题,当日期时间减少毫秒时,它是00.日期时间力毫秒

如何强制日期时间不削减毫秒?我想将它作为DateTime返回,而不是string

[ 
    { 
    "date": "2013-04-09T09:21:32", 
    "route_id": 60256, 
    "route_name": "Karlstad Malung", 
    "type": "Comment" 
    }, 
    { 
    "date": "2013-04-09T09:20:58.91", 
    "route_id": 60256, 
    "route_name": "Test", 
    "type": "Comment" 
    }, 
+0

如果您认为它不符合标准,WCF管道可自定义,我想您可以使用您自己的JSON序列化程序,或者报告Microsoft /您使用的错误。或者如果是这样,请使您的呼叫代码符合标准! – 2013-04-09 07:39:07

您可以使用“.F”格式化修改:

DateTime dateValue = new DateTime(2008, 7, 16, 8, 32, 45, 0); 
Console.WriteLine("{0} seconds", dateValue.ToString("s.f")); 
Console.WriteLine("{0} seconds", dateValue.ToString("s.ff")); 
Console.WriteLine("{0} seconds", dateValue.ToString("s.ffff")); 
// The example displays the following output to the console: 
// 45.0 seconds 
// 45.00 seconds 
// 45.0000 seconds 

第二步是修改WCF序列化使用这种DateTime格式。