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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With