如何在输入中放置时间=“0”;时间“;在html中使用javascript

How to place the time in the input ="time" in html using javascript

本文关键字:时间 javascript html 输入      更新时间:2023-09-26

我尝试用comments mark将代码设置为输入类型。我正在尝试获取输入类型,以便添加specific GMT

<html>
<head>
<script language="JavaScript">
function calcTime(city, offset) {
    d = new Date();
    utc = d.getTime() + (d.getTimezoneOffset() * 60000);
    nd = new Date(utc + (3600000*offset));
    document.write("'n't'n");
    return "<br>"+"The local time in " + city + " is " + nd.toLocaleString()+ "<br>" ;
}
// get Singapore time
//document.write(calcTime('Singapore', '+8'));
//document.getElementById("tim").value = "(calcTime('Singapore', '+8'))";
//document.write("tim").value = (calcTime('Singapore', '+8'));
// get London time
//document.write("tim".value(calcTime('London', '+1')));
// I TRIES THE CODES ^ BUT IT IS NOT 
document.write(calcTime('Moscow', '+3'));
</script>
</head>
<body>
<input type="time" name="tim" id="tim" value ="">
</body>
</html>

您可以尝试使用选择器的.value。如下:

document.getElementById("tim").value = "22:53:05";

更新:

检查此Fiddle演示