ie下获取某个时间的毫秒值

在IE浏览器下,若要获取某个时间的毫秒值('2017-12-07 16:49:56.0'),必须先将该时间字符串转换格式再去转换成毫秒值;javascript

//空判断,也能够用underscore的_.isEmpty()函数
       isEmpty : function(fData) {
			if (typeof fData == "function") {
				return false;
			}
			return typeof fData == "undefined" || fData == undefined || fData == null || 
                   fData.length == 0 || fData == 'null' || (fData != false && fData == '');
		},
		isNull : function(fData, replaceData) {
			return _this.isEmpty(fData) ? replaceData : fData;
		},
        strToDate : function(str) {
			if (_this.isEmpty(str)) {
				return null;
			}
			var converted = Date.parse(str);
			var myDate = new Date(converted);
			if (isNaN(myDate)) {
				if (str.indexOf(":") != -1) {
					str = str.replace(" ", "-");
					str = str.replace(":", "-");
					str = str.replace(":", "-"); // 第二个时间
					var arys = str.split('-');
					myDate = new Date(arys[0], --arys[1], arys[2], _this.isNull(arys[3], 0), 
                    _this.isNull(arys[4], 0), _this.isNull(arys[5], 0));
				} else {
					var arys = str.split('-');
					myDate = new Date(arys[0], --arys[1], arys[2]);
				}
			}
			return myDate;
		},
        var strTime = '2017-12-07 16:59:55.0'; 
        var dateTime = strToDate(strTime);
        var timeValue = Date.parse(dateTime);
        console.log('至该时间的毫秒值:' + timeValue);
相关文章
相关标签/搜索