Tuesday, April 21, 2009

Formatting Dates In Flex

If you have been working with any of the new AGS apis (at least Flex or DOJO in my experience), you have probably encountered one of these:

Mon Dec 31 17:00:00 MST 2001

This is the date string returned within a query result featureSet.

var assessmentDateString:String = featureSet.attributes[0][assessmentDateLabel];


Not very usable really. However, there is hope! Flex has a nice little class called DateFormatter. DateFormatter does alot of stuff but what is really handy is its ability to parse pretty much any date string into a real date object. The langref gives you all the details on how to do this but converting the date string above into an actual date is a simple as:

private function getFormattedDate(dateString:String):Date
{
var formatter:DateFormatter = new DateFormatter(); formatter.formatString = "EEE MMM DD H:NN:SS YYYY" var newDate:Date = new Date(formatter.format(dateString)); return newDate;
}


Take special notice that the formatString pattern does not try to match the "MST" portion of the date string. This portion is simply ignored. This is not because literal characters aren't allowed, just not caps. Lowercase along with punctuation and numbers can be used in the pattern if needed.

Thursday, April 16, 2009

Greg's Projects

Started a new stream regarding some of my personal projects. The main thrust right now being my basement finish (I am going to try and do it mostly myself). If interested in learning from my screw-ups, have a look.

Greg's Projects Blog