How to convert a String to long in javascript?

I have a millisecond timestamp that I need to convert from a String to long. Javascript has a parseInt but not a parseLong. So how can I do this?

Thanks

Edit: To expand on my question slightly: given that apparently javascript doesn't have a long type, how can I do simple arithmetic with longs that are initially expressed as strings? E.g subtract one from the other to get a time delta?

Answers


JavaScript has a Number type which is a 64 bit floating point number*.

If you're looking to convert a string to a number, use

  1. either parseInt or parseFloat. If using parseInt, I'd recommend always passing the radix too.
  2. use the Unary + operator e.g. +"123456"
  3. use the Number constructor e.g. var n = Number("12343")

*there are situations where the number will internally be held as an integer.


It's because there is no long in javascript.

http://javascript.about.com/od/reference/g/rlong.htm


Need Your Help

Android: How to pause and resume a Count Down Timer?

java android onpause countdowntimer

I have developed a Count Down Timer and I am not sure how to pause and resume the timer as the textview for the timer is being clicked. Click to start then click again to pause and to resume, click...

Dynamic dispatch in Haskell

haskell functional-programming dynamic-dispatch

Programs written in, for example, Java rely a lot on dynamic dispatch.