AS3中的日期格式

时间:2015-06-23 22:06:57

标签: php mysql actionscript-3 flash

我希望我的AS3代码在MYSQL表中检索特定日期。

我遇到了格式问题。 当我写作时,在我的AS3代码中:

memberCombo.addItem( {label: "2015-06-23" } );
memberCombo.addEventListener(Event.CHANGE, checkComplete);

function checkComplete(evt:Event):void {

    var myVariables:URLVariables = new URLVariables();
        myVariables.username = evt.target.value;
        var myRequest:URLRequest = new URLRequest("http://www.***.com/sql_date.php");

    myRequest.method = URLRequestMethod.POST;
    myRequest.data = myVariables;
    trace(myRequest.data);

trace(myRequest.data);结果2015%2D06%2D23 所以它似乎在我的SQL表中搜索这个2015%2D06%2D23(所以它找不到它,因为我的表中的日期格式是YY-M-D)。

您知道我如何告诉我的AS3代码以这种格式在我的SQL表中查找日期:YY-M-D

谢谢

修改

这就是我所做的(但我犯了一个错误,因为它产生了一个错误):

    var myRequest:URLRequest = new URLRequest("http://www.****.com/sql_result.php");

myRequest.method = URLRequestMethod.POST;

    myRequest.data = myVariables;
    var myAS3Date;
    var myRequestString = "";
    myRequestString=dtAS3toMysql(myAS3Date);

function dtAS3toMysql( date:Date ):String {
    var s:String = date.fullYear + '-';

    // add the month
    if( date.month < 10 ) {
        s += '0' + ( date.month + 1 ) + '-';
    } else {
        s += ( date.month + 1 ) + '-';
    }

    // add the day
    if( date.date < 10 ) {
        s += '0' + date.date;
    } else {
        s += date.date;
    }

    return s;
}

1 个答案:

答案 0 :(得分:1)

public static function dtMysql2AS3( s:String ):Date {
        var a:Array = s.split( '-' );
        return new Date( a[0], a[1] - 1, a[2] );
    }


public static function dtAS3toMysql( date:Date ):String {
    var s:String = date.fullYear + '-';

    // add the month
    if( date.month < 10 ) {
        s += '0' + ( date.month + 1 ) + '-';
    } else {
        s += ( date.month + 1 ) + '-';
    }

    // add the day
    if( date.date < 10 ) {
        s += '0' + date.date;
    } else {
        s += date.date;
    }

    return s;
}