Add 6 hours to current time and display to page

后端 未结 5 1070
执笔经年
执笔经年 2020-12-10 01:40

So, I\'m trying to add some labels to a graph, and I want to add them to 6, 12, 18, and 24 hours on the horizontal axis.

I want to write these times in a \"hh:mm\"

5条回答
  •  时光说笑
    2020-12-10 02:01

    based on How to add 30 minutes to a JavaScript Date object?

    var d1 = new Date ();
    var d2 = new Date ( d1 );
    d2.setHours ( d1.getHours() + 6 );
    

    https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date will show how to manipulate Date objects.

    added your code with some fixes. edited to add second document.write

    
    

提交回复
热议问题