Search code examples
javascriptdatejs

datejs overwriting Date in javascript


I am using date js to quickly parse any string into a date and it is working perfectly. However I need to also parse a timestamp.

var temp_string = "1484120122526";
var date = new Date(temp_string); 

It gives back

NaN –

Regular javascript Date object does this, but I can't find a way for datejs to do it. And since it overwrites the Date object, I am stuck. Can datejs parse timestamps? or is there a way for me to call new Date() and reference the original date object?


Solution

  • Even though dateJS does indeed overwrite the default js Date class, the fault was on my side, I did not see in the documentation the fact that timestamp has to be an int, as I was looking everywhere in the dateJS documentation not the Date one.

    so the code should be:

    var temp_int = 1484120122526;
    var date = new Date(temp_int);