:: Forum >>

DateTime Formatting

I looked in these forums for a way to use a datetime from MySQL, but there were no answers.

I decided to subclass the AW.Formats.Date class and add a MYSQL format.
Below is what I have, and it works, just wondering if there's a way to make it quicker with regex or something.

AW.Formats.DateTime = AW.Formats.Date.subclass();

AW.Formats.DateTime.create = function(){

var obj = this.prototype;

var MYSQL = function(data){
//2004-12-21 12:18:40.0
var retDate = new Date();
var aryDT = data.split(" ");
var myDate = aryDT[0].split("-");
var myTime = aryDT[1].split(":");
var mySeconds = myTime[2].split(".");

retDate.setFullYear(myDate[0]);
retDate.setMonth(myDate[1]);
retDate.setDate(myDate[2]);
retDate.setHours(myTime[0]);
retDate.setMinutes(myTime[1]);
retDate.setSeconds(mySeconds[0]);
retDate.setMilliseconds(mySeconds[1]);

var value = retDate.getTime();
return isNaN(value) ? this._valueError : value;
};

obj.setDataFormat = function(format){
if (format == "RFC822") {
this.dataToValue = RFC822;
}
else if (format == "ISO8601" || format == "ISO8061") {
this.dataToValue = ISO8601;
}
else if (format == "MYSQL") {
this.dataToValue = MYSQL;
}
else {
this.dataToValue = auto;
}
};

};

datetime = new AW.Formats.DateTime;
datetime.setDataFormat("MYSQL");
Jonathan Doklovic
Friday, March 10, 2006

This topic is archived.


Back to support forum

Forum search