There were a lot of answered questions about converting milliseconds to date format but none of them was able to solve my problem.
I have a string (and not a time) coming in my javascript code. It is of the format as below
1380549600000+1000
When I try to parse it using the following code it gives me "invalid date" error.
My main objective is to convert this string to dd/mm/yyyy format. So was thinking of converting it into date and applying methods like "getMonth", etc
<script>
var modDate = "1380549600000+1000"; //Note the value is in "" hence a string
var d = new Date(modDate); //Invalid date error here
document.getElementById("demo").innerHTML = d;
</script>
The following works just fine. But this is not the format I am getting.
<script>
var modDate = 1380549600000+1000; //Note the value is no longer in ""
var d = new Date(modDate); //No problems here
document.getElementById("demo").innerHTML = d;
</script>
Please help. Thanks in advance.
Cheers.
edit:-
eval is not the best approach, it is not safe to use eval, so use this instead:-
I am not sure if you need that added 1000, if you don't, it could be done in one line as :-
older approach :-