there appears to be a bug in the ajax client code. First, try this in javascript:
var testDate = new Date();
var testDateString = testDate.localeFormat("yyyy-MM-ddTHH:mm:ss.fffffffzzz");
I'm in New York, so the value of testDateString = "2007-10-12T12:10:56.34534+4:00" or something like that.
now try doing this in c#
DateTime testDate = DateTime.Now;
testDateString = testDate.toString("yyyy-MM-ddTHH:mm:ss.fffffffzzz");
in this case, the value of testDateString is equal to something like: "2007-10-12T12:10:56.34534-4:00"
now to see some real fun, add this to the above Javascript:
var messedUpDate = Date.parseLocale(testDateString, "yyyy-MM-ddTHH:mm:ss.fffffffzzz");
you'll find that the messed up date is not equal to the original test date. however in c#
DateTimemessedUpDate = Date.ParseExact(testDateString,"yyyy-MM-ddTHH:mm:ss.fffffffzzz",CultureInfo.CurrentCulture.DateTimeFormat);
will yield a date equivalent to testDate.
Is this a bug? or am I misusing/misunderstanding the localeFormat method?
Hi,
I think parseLocal create a date from a localized date string. I think it works only when you do the followings (it is from the documentation):
Remarks
Use the pareseLocale function to create anobject of type Date from a string. If you provide no custom formats,this function uses theSys.CultureInfo.CurrentCulture property to determine the culture value.
To create a date from a locale-specific string that uses the current culture, set theEnableScriptGlobalization property of theScriptManager control totrue. You must also modify settings in the Web.config file so that theculture attribute of the<globalization> section is set toauto.
I don't think this is a localization problem. As you can see by the results of running my code, all the strings do parse correctly as dates, the problem is that the resulting dates are incorrect.
Ok, I see.
First test:
var testDate = new Date();
var testDateString = testDate.localeFormat("yyyy-MM-ddTHH:mm:ss.fffffffzzz");
window.alert( testDateString ); //2007-10-17T10:11:16.0310310-02:00 <-- good
var messedUpDate = Date.parseLocale(testDateString, "yyyy-MM-ddTHH:mm:ss.fffffffzzz");
window.alert( messedUpDate ); //Wed Oct 17 200714:11:16 GMT+0200 (Central Europe Daylight Time) <-- total wrong!!!
Second test:
var testDate = new Date();
var testDateString = testDate.localeFormat("yyyy-MM-ddTHH:mm:ss.fffffff");
window.alert( testDateString ); //2007-10-17T10:13:32.5155155 <-- good
var messedUpDate = Date.parseLocale(testDateString, "yyyy-MM-ddTHH:mm:ss.fffffff");
window.alert( messedUpDate ); //Wed Oct 17 2007 10:13:32 GMT+0200 (Central Europe Daylight Time) <-- also good
Maybe localFormat and parseLocal don't like time zone formatting?!
The issue on the timezone offset was a bug in the javascript date formatting, and will be fixed in the next release. The reason for the discrepancy between parse and format was that parsing didn't have the same bug.
No comments:
Post a Comment