Search code examples
windows-8globalizationwinjs

DateTimeFormatter


if I run the following:

var newdate = new Date();
var dt = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("shortdate");
var date = dt.format(newdate);

I get back something like this 10/14/2012 which is fine, however if I throw that into a url for WinJS.xhr it changes it to ?10?/?4?/?2012

Sample code for service call

var urlAddress ="http://www.communitymegaphone.com/ws/CMEventDS.svc/GetEventsByDistance?Lat='" + mapCenter.latitude + "'&Lon='" + mapCenter.longitude + "'&Dist=" + eventsByDistance + "&$filter=(starttime%20gt%20datetime'" + date  + "')&$orderby=starttime%20asc&$format=json";

WinJS.xhr({
        type: "GET",
        url: urlAddress
    }).then(processSuccess, processError);

If I use plain old javascript datetime everything works fine.

Did I miss a setting somewhere? I have also tried changing the encoding of the url to different formats with no luck.


Solution

  • The DateTimeFormatter is specifically intended to be user facing. When you create a url, you are no longer user facing, but backend facing. You need to use a standard date format for that (like iso 8601), not one that adjusts to the language of the user. The characters identified by the question marks are left-to-right and right-to-left marks that ensure the string appears correctly even in embedded content.