【问题标题】:wcf service unable to parse datetime from javascript running in iewcf 服务无法从 ie 中运行的 javascript 解析日期时间
【发布时间】:2013-04-11 23:02:24
【问题描述】:

我有一个 WCF 服务,其方法定义如下:

<WebGet(), OperationContract()>
    Public Function GetScene(cameraId As Integer, time As Date, bufferSize As Integer) As Scene

和看起来像这样的javascript:

time = new Date("04/09/2013 23:59")
$.getJSON('../Services/CameraViewerService.svc/GetPreviousScene', 'cameraId=' + _cameraId + '&time=' + time.toUTCString() + '&bufferSize=20', function () {...});

在 chrome 和 firefox 中,查询字符串中的日期最终看起来像这样:

Tue, 09 Apr 2013 23:59:00 GMT

WCF 服务可以很好地使用它,但是当我使用 Internet Explorer 9 时,查询字符串中的日期如下所示:

Tue, 9 Apr 2013 23:59:00 UTC

WCF 服务抛出异常:

The string was not recognized as a valid DateTime. There is an unknown word starting at index 26.

让它适用于所有浏览器的最佳方法是什么?

【问题讨论】:

    标签: javascript .net vb.net wcf internet-explorer


    【解决方案1】:

    你可以使用toISOString()

    这应该可以解析,因为它是公认的标准日期和时间之一formats

    在 IE8 和 earlier 中不支持 toISOString(),但我的第一个链接中的 Mozilla 文档有一个示例 shim,如果不支持该功能,您可以使用它。

    【讨论】:

      猜你喜欢
      • 2020-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-17
      相关资源
      最近更新 更多