Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript中ie浏览器的日期解析问题_Javascript_Jquery_Datepicker - Fatal编程技术网

javascript中ie浏览器的日期解析问题

javascript中ie浏览器的日期解析问题,javascript,jquery,datepicker,Javascript,Jquery,Datepicker,我的日期选择器格式日期=2014年7月21日上午11:00 我想将datepicker转换为时间戳格式,如2014-07-21T11:00:00。在javascript中 为此,我写了这样的文章 var now = new Date(date); var year = now.getFullYear(); var month = now.getMonth()+1; var day = now.getDate(); var hour = now.getHours(); v

我的日期选择器格式日期=2014年7月21日上午11:00

我想将datepicker转换为时间戳格式,如2014-07-21T11:00:00。在javascript中

为此,我写了这样的文章

var now = new Date(date);
var year    = now.getFullYear();
var month   = now.getMonth()+1; 
var day     = now.getDate();
var hour    = now.getHours();
var minute  = now.getMinutes();
var second  = now.getSeconds(); 
var convertedDate = year+'-'+month+'-'+day+'T'+hour+':'+minute+':'+second; 
它在chrome和firefox中运行良好,但在InternetExplore中失败了

我得到的日期值像楠楠:楠楠:楠

请帮忙。如何解决这个问题

function changeDateFormat(date){
/*split date into three parts */
var dateParts = date.split(" ");

if (dateParts.length != 3) { 
    return false; }

/*split Time into three parts*/
var time = dateParts[1].split(":");
var second = 00;

/*split minutes and (AM or PM) into two parts*/
var checkAM = dateParts[1];

 /*if time is PM then adding 12hrs  for to get 24hrs format*/
if((checkAM[1] == "pm") ||(checkAM[1] == "PM") ){
    time[0] = Number(time[0])+Number(12);
}
var months = ['January', 'February', 'March', 'April', 'May', 'June',
              'July', 'August', 'September', 'October', 'November', 'December'];

    var date = dateParts[0].split("-");
    var splitMonth = date[0];

    var month;
    for(month=0; month<months.length ; month++){
        if(months[month] == splitMonth){
            var monthDigit1 = Math.floor((month+1) / 10);
            var monthDigit2 = (month+1) % 10;

            return date[2] + '-' + monthDigit1 + '' + monthDigit2+ '-' + date[1] + 'T' + time[0] + ':' + time[1] + ':'+ second;
        }
    }

}

请参见::要获得与自定义格式一致的行为,您可能需要找到一个提供parse-exact或parse-with-format选项的库。JavaScript只有一个功能。所有其他的都由引擎决定是否支持。