RKCY
RKCY

Reputation: 4135

convert Date Format yyyy-mm-dd to dd-mm-yyyy in flex

I have a requirement. I have a date format as yyyy/mm/dd and I want to convert this format to mm/dd/yyyy in action script.

I had tried to parse to this format, it is not working. Can any one of you please help me?

Upvotes: 0

Views: 1315

Answers (2)

Ohas
Ohas

Reputation: 1871

If we're opting for string manipulation, why not this:

'2010/05/14'.replace(/(\d{4})\/(\d{2})\/(\d{2})/, '$2/$3/$1')

Upvotes: 0

RIAstar
RIAstar

Reputation: 11912

var s:String = "2012/03/05";
var dateParts:Array = s.split('/'); //['2012', '03', '05']
//take off the first element and add it back at the end
dateParts.push(dateParts.shift());  //['03', '05', '2012']
s = dateParts.join('/');            //'03/05/2012'
trace(s);

Upvotes: 3

Related Questions