Javascript Date.parse returns NaN in BlackBerry Browser

This is the code I'm trying to run in a browser for the Blackberry 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 GMT information is present in the string that I pass to the method parse, it returns NaN, whereas it returns a value if GMT information is not available. But I can’t remove the GMT part from my string.

Any idea why this fails ?. Please note that this only happens in blackberries.

Thanks in advance.

+5
source share
2 answers

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

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

then analyze 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);

, datejs.

+4

, BlackBerry . GMT.

// manually create date string because of BlackBerry parse method
var dateStr=dateObj.getDay()+' '+dateObj.getDate()+' 'dateObj.getMonth()+' '+dateObj.getFullYear()+' '+dateObj.getHours()+':'+dateObj.getMinutes()+':'+'00';
var mydate = Date.parse(dateStr); // works
0

All Articles