2017-01-31 57 views
2

我试图在Internet Explorer中调试一个非常奇怪的字符串长度的问题11.Javascript字符串正确长度

我不能工作了,为什么它是告诉我,字符串“2017年1月3日”的长度为15?

有谁能告诉我我做错了吗?

enter image description here

下面是函数

function stringToUKDate(strDate) { 
debugger; 
newDate = strDate.trim().substr(0, 10); 
var dateSplit = newDate.split("/"); 
var newDate = new Date(dateSplit[2], dateSplit[1] - 1, dateSplit[0], 0, 0, 0); 
// return the new date 
return newDate; 
} 

encodeURIComponent方法(strDate)给了我 %E2%80%8E01%E2%80%8E%2F%E2%80%8E02% E2%80%8E%2F%E2%80%8E2017

+3

请发送代码 – Weedoze

+5

'encodeURIComponent(strDate)'给你什么...? – deceze

+9

猜测是,字符串中有一些不可打印的字符。 – Sirko

回答

0

我认为这个问题来自你的类型,也许转换增加了一些字符(也许不间断空格或不显示cha rs但计数...) 尝试日期格式或一个tostring