Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toLocaleTimeString returns non-ascii characters #883

Closed
virdun opened this issue Apr 28, 2016 · 2 comments
Closed

toLocaleTimeString returns non-ascii characters #883

virdun opened this issue Apr 28, 2016 · 2 comments

Comments

@virdun
Copy link

virdun commented Apr 28, 2016

// Issue in Edge but not in chrome
var t = dt.toLocaleTimeString(); // Say it returns 13:04:26
var tArr = t.split(':');
console.log(parseInt(tArr[0], 10); // returns NaN in Edge, other browsers return 13
console.log(+tArr[0]); // returns NaN in Edge, other browsers return 13
console.log(1 * tArr[0]); // returns NaN in Edge, other browsers return 13

// Solution to the problem for Edge and possibly IE11
function removeNonAscii(str) {
var regx = new RegExp("[^\u0000-\u007F]", "g");
return str.replace(regx, '');
}
var t = removeNonAscii(dt.toLocaleTimeString()); // Say it returns 13:04:26
var tArr = t.split(':');
console.log(parseInt(tArr[0], 10); // returns 13
console.log(+tArr[0]); // returns 13
console.log(1 * tArr[0]); // returns 13

@jianchun
Copy link

This is the same issue as #599

@virdun
Copy link
Author

virdun commented Apr 28, 2016

Yes, that is correct. I did not find that one before I posted. Sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants