code-tutorial.com

The best resources for developers

Actionscript 3 - Fastest way to parse yyyy-mm-dd hh:mm:ss to a Date object?

private function parseUTCDate( str : String ) : Date {
    var matches : Array = str.match(/(dddd)-(dd)-(dd) (dd):(dd):(dd)Z/);

    var d : Date = new Date();

    d.setUTCFullYear(int(matches[1]), int(matches[2]) - 1, int(matches[3]));
    d.setUTCHours(int(matches[4]), int(matches[5]), int(matches[6]), 0);

    return d;
}
private function parseDate( str : String ) : Date {
    var matches : Array = str.match(/(dddd)-(dd)-(dd)/);

    var d : Date = new Date();

    d.setUTCFullYear(int(matches[1]), int(matches[2]) - 1, int(matches[3]));

    return d;
}

Tags: apache-flex actionscript-3

Source: By Matt MacLean as answer to the question

This code snippet was collected from stackoverflow, and is licensed under CC BY-SA 3.0


Related code-snippets: