添加6小时到当前时间并显示到页面 [英] Add 6 hours to current time and display to page
问题描述
所以,我正在尝试为图形添加一些标签,我想在水平轴上将它们添加到6,12,18和24小时。
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.
我想用hh:mm格式(例如23:10,10:10,11:10和17:10)写这些时间本地(计算机)时区?
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?
有人可以帮我吗?
推荐答案
基于如何添加30分钟到一个JavaScript Date对象?
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 将显示如何操作Date对象。
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date will show how to manipulate Date objects.
为您的代码添加了一些修复程序。编辑
以添加第二个document.write
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>
这篇关于添加6小时到当前时间并显示到页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!