D3图表 - JS - 增加时间

问题描述 投票:0回答:1

希望能得到一些指导。

我正在玩这个 - https://codepen.io/HD10805/pen/QoaVdL

在JS元素中,有一节我相信Time的数据是生成和编译的。

function renderTime() {

var now = new Date();
var today = now.toDateString();
var time = now.toLocaleTimeString();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
var milliseconds = now.getMilliseconds();
var newSeconds = seconds+ (milliseconds/1000);

基本上,我希望能够增加或减少小时数,以显示其他国家/地区在其他时区的时间。

提前致谢。

javascript d3.js charts
1个回答
0
投票

你可以使用setHours

let date = new Date()

console.log(date)

let hours = date.getHours()

date.setHours(2 + hours)

console.log(date)
© www.soinside.com 2019 - 2024. All rights reserved.