Reputation: 1371
I have a WCF service with a method defined like so:
<WebGet(), OperationContract()>
Public Function GetScene(cameraId As Integer, time As Date, bufferSize As Integer) As Scene
and javascript that looks like this:
time = new Date("04/09/2013 23:59")
$.getJSON('../Services/CameraViewerService.svc/GetPreviousScene', 'cameraId=' + _cameraId + '&time=' + time.toUTCString() + '&bufferSize=20', function () {...});
in chrome and firefox the date in the query string ends up looking like this:
Tue, 09 Apr 2013 23:59:00 GMT
and the WCF service consumes it just fine, but when I use internet explorer 9 the date in the query string looks like this:
Tue, 9 Apr 2013 23:59:00 UTC
and the WCF service throws an exception:
The string was not recognized as a valid DateTime. There is an unknown word starting at index 26.
What is the best way to get this to work for all browsers?
Upvotes: 1
Views: 399
Reputation: 5841
You could use toISOString()
.
This should hopefully parse OK as it's one of the recognised standard date and time formats.
In IE8 and earlier toISOString()
is not supported but the Mozilla documentation from my first link has an example shim which you can use if there is not support for the function.
Upvotes: 1