Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Date.parse returning NaN in blackberry browser

This is the code I am trying to run in blackberry simulator browser (OS V6.0).

<html>
<body>

<script type="text/javascript">
var d = Date.parse("Tue Oct 25 2011 18:33:17 GMT+0230");
var d1 = Date.parse("Tue Oct 25 2011 18:33:17");
document.write(d+"::::::"+d1);

</script>

</body>
</html>

Whenever the GMT information is there is in the string I pass to parse method,it returns NaN,whereas it is returning a value if the GMT information is not there.But I cannot remove the GMT part from my string.

Any idea why this is failing?.Please note that it is happening in blackberry only.

Thanks in advance.

like image 223
user700284 Avatar asked Oct 10 '22 16:10

user700284


1 Answers

As said in the comments, you can remove the GMT part:

var gmt = str.indexOf("GMT");
var newDate = str.substr(0,gmt-1)

then parse the data:

var d = Date.parse(newDate);

and finally, add the GTM part:

var offset_hour = str.substr(gmt+3, 3);
var offset_min = str.substr(gmt+6);
d.addMinutes(60 * offset_hour + offset_min);

The code is not tested and the last call corresponds to the datejs library.

like image 74
Ivan Avatar answered Oct 13 '22 11:10

Ivan