1

Try Following Code in IE 11.

var d= new Date();
var lt=d.toLocaleTimeString();
var localeTime= lt.split(“:”);
var str=parseInt(localeTime[0]);
  1. parseInt is returning NaN.
  2. Try passing the value at localeTime[0] directly to parseInt() . It gives correct output which is numeric form of String passed to parseInt() .
  3. Try localeTime[0]===Value at localeTime[0] . The output is false.
5
  • why don't you call the appropriate getters? Commented Sep 29, 2016 at 17:49
  • Also fails with Number(localeTime[0]); Commented Sep 29, 2016 at 17:57
  • I will do that , I just want to know why the parseInt() is not able to convert string from the array to number. Commented Sep 29, 2016 at 17:57
  • 1
    Check out: connect.microsoft.com/IE/feedback/details/863366/… MS claims it is a feature. Commented Sep 29, 2016 at 18:20
  • Thanks everyone for quick reply .@JonSG let me go through the link you send . Commented Sep 29, 2016 at 18:34

1 Answer 1

1

If you run localeTime[0].length you will see that it returns 4.

localeTime[0] // "20"
localeTime[0].length // 4
x.charCodeAt(0) // 8206 -> ???
x.charCodeAt(1) // 50 -> "2" as expected
x.charCodeAt(2) // 48 -> "0" as expected
x.charCodeAt(3) // 8206 -> ???

For some reason in IE there are also two additional characters at start and end of token.

In order to make it work you would need to normalize string by removing all non-alphanumeric characters.

parseInt(localeTime[0].replace(/\W/, '')) // returns 20 as expected
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Yariash for clarifying the concept .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.