Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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" format (23:10, 05:10, 11:10, and 17:10 for example) for the local (computer) timezone?

Can someone help me with this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
132 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

<script type="text/javascript"> 
var timer = 24; 
var d1 = new Date(); 
var d2 = new Date();
d1.setHours(+d2.getHours()+(timer/4) ); 
d1.setMinutes(new Date().getMinutes()); 
document.write(d1.toTimeString("hh:mm"));
document.write(d1.getHours()+":"+d1.getMinutes());
</script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...