Nidhi
Nidhi

Reputation: 795

How can i convert string datatype to date datatype in flex

I have to convert one string type field to date datatype in flex.

What can I do solve this problem?

Upvotes: 6

Views: 8932

Answers (3)

invertedSpear
invertedSpear

Reputation: 11054

import mx.controls.DateField;

var dateString:String = " 25/02/2009";
var date:Date= DateField.stringToDate(dateString,"DD/MM/YYYY");

with credit to: http://amthekkel.blogspot.com/2009/02/flex-converting-date-string-to-date.html

Upvotes: 6

girija
girija

Reputation: 41

var str:String = "25/02/2009"
var d:Date = new Date(str);

or

we can use a custom DateUtils class

package 
{
  import mx.formatters.DateFormatter;

  public class DateUtils extends DateFormatter
 {
    public function DateUtils()
   {
     super();
   }



  public static function parseString (str:String):Date {
      return parseDateString(str);
  }

 }
}

Upvotes: 4

Jason Towne
Jason Towne

Reputation: 8050

You can also use the Date.parse function with the Date.setTime function to create a new Date object from a string.

var myDateString:String = "05/10/2011";
var myDate:Date = new Date();

myDate.setTime(Date.parse(myDateString));

Upvotes: 0

Related Questions