datatime类型正确格式
yy-mm-dd hh:mm:ss

解决方案 »

  1.   

    <script>
    var d = new Date();
    d = formatDateTime(d,"datetime");
    //就可以直接把d的值提交到数据库了.
    alert(d);function formatDateTime(date, mode)
    {
    /*
     *--------------- formatDateTime(date, mode) -----------------
     *formatDateTime(date, mode) 
     * 功能:格式化时间的输入出格式.
     * 参数:date,时间实例.
     * 参数:mode,字符串:"date","time","datetime"
     * 返回:时间输出字符串
     *--------------- formatDateTime(date, mode) -----------------
     */
        function getDateString(date){
            var years=date.getFullYear();
            var months=date.getMonth()+1;
            var days=date.getDate();        if (months<10) months="0"+months;
            if (days<10) days="0"+days;        return years+"-"+months+"-"+days;
        }    function getTimeString(date){
            var hours=date.getHours();
            var minutes=date.getMinutes();
            var seconds=date.getSeconds();        if (hours<10) hours="0"+hours;
            if (minutes<10) minutes="0"+minutes;
            if (seconds<10) seconds="0"+seconds;        return hours+":"+minutes+":"+seconds;
        }    if (typeof(date)=="object" && !isNaN(date)){
            if (!mode) mode="datetime";
            switch (mode){
                case "date":{
                    return getDateString(date);
                    break;
                }
                case "time":{
                    return getTimeString(date);
                    break;
                }
                case "datetime":{
                    return getDateString(date)+" "+getTimeString(date);
                    break;
                }
                default:{
                    return getDateString(date)+" "+getTimeString(date);
                    break;
                }
            }
        }
        else
        return "";
    }
    </script>