javascript - Issue with .toISOString() function -
consider following code html + javascript:
<!doctype html> <html> <body> <p id="demo">click button display date after changing hours, minutes, , seconds.</p> <button onclick="myfunction()">try it</button> <script> function myfunction() { var d = new date(); d.sethours(0,0,0,0); document.write(d + '<br/>'); document.write('iso date '+ d.toisostring() + '<br/>'); //i want 2013-04-17t00:00:00.000z } </script> </body> </html>
output:
thu apr 18 2013 00:00:00 gmt+0530 (india standard time) iso date 2013-04-17t18:30:00.000z
could on understanding difference in date & time
var d = new date(); d.sethours(-12, d.gettimezoneoffset(), 0, 0); //removing timezone offset , 12 hours console.log(d.toisostring()); //2013-04-17t00:00:00.000z
i don't know, why need iso date day earlier, in case typo:
var d = new date(); d.sethours(0, -d.gettimezoneoffset(), 0, 0); //removing timezone offset. console.log(d.toisostring()); //2013-04-18t00:00:00.000z
Comments
Post a Comment