js时间字符串转Date对象


    var DATE_REGEXP = new RegExp("(\\d{4})-(\\d{2})-(\\d{2})([T\\s](\\d{2}):(\\d{2}):(\\d{2})(\\.(\\d{3}))?)?.*");
    function toDate(dateString){
        if(DATE_REGEXP.test(dateString)){
            var timestamp = dateString.replace(DATE_REGEXP, function($all,$year,$month,$day,$part1,$hour,$minute,$second,$part2,$milliscond){
                var date = new Date($year, $month,$day, $hour||"00", $minute||"00", $second||"00", $milliscond||"00");
                return date.getTime();
            });
            var date = new Date();
            date.setTime(timestamp);
            return date;
        }
        return null;
    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM