View Full Version : [SOLVED] Date Initialization is not correct.

27 Nov 2009, 9:46 AM
I am having an issue with date, and the date output, I am relying on the localization to do the work for me, because my site will be used on internationally. However, when I initialize the object with a date and I send the request to the server, it gives me this error.

Here is the error, I am getting.

System.ArgumentException: Cannot convert Fri Nov 27 2009 10:31:59 GMT-0700 (Mountain Standard Time) to System.DateTime.
Parameter name: type ---> System.FormatException: String was not recognized as a valid DateTime.
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)

params in request

params: {
// other params...
fromDate: Tue Oct 27 2009 00:00:00 GMT-0600 (Mountain Daylight Time)
toDate: Fri Nov 27 2009 10:31:59 GMT-0700 (Mountain Standard Time)

However, when I pass this criteria to a form, using:


// Later in code
params = form.getValues();

I get a newly formatted date, and these params are good when passed to the .NET service.

params: {
// other params...
fromDate: 10/27/2009
toDate: 11/27/2009

In my Ext.ux.Criteria extended class is the constructor

constructor: function (config) {
config = config || {};

"beforechange": true,
"changed": true,
"beforeentityadd": true,
"entityadded": true

this.listeners = config.listeners;

Ext.apply(this,config, {
entities: new Array(),
toDate: new Date(),
fromDate: new Date(Today.getFullYear(), Today.getMonth() - 1, Today.getDate())

Should I be using something else to initialize the date?

1 Dec 2009, 7:34 AM
I used the Date.js object in lib\src\util of EXT JS to get the pattern I needed, and it returns the string. I am assuming the datefield object understands the dates. It doesn't seem elegant, but it works for now.

toDate: new Date().format(Date.patterns.ShortDate),

If I have international formatting problems, I'll deal with it when I come to it. (:|