【发布时间】:2014-10-16 16:03:45
【问题描述】:
您好,我正在编写一个返回 DateTime 的 JSON 网络服务。
它以 EPOCH 格式返回日期时间。是否可以修改它返回的 JSON 日期格式。
代码sn-p
[ServiceContract]
public interface ITMAppServices
{
[OperationContract]
[WebGet(UriTemplate = "/Test",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
DateTime GetData();
}
实际实现
public class TMAppServices : ITMAppServices
{
public DateTime GetData()
{
return DateTime.Now;
}
}
我只是在 C# 中返回 datetime.now
以 EPOCH 格式输出:
"/日期(1413399311687+0300)/"
我希望以 C# 返回的相同格式输出 或者如果我从 SQL 获取日期时间
【问题讨论】:
-
return DateTime.Now;以EPOCH格式返回日期? -
是的。它实际上是一个 JSON 网络服务。当我以这种方式运行服务时 localhost:64964/TMAppServices.svc/Test 它返回 "\/Date(1413403048647+0300)\/"