可以将上述代码中 指定时间(样式为 年-月-日 时:分)<input type="text" value="2023-01-02 16:00"name="" id="date"><br/> 修改为获取当前时间的代码,当前时间精确度为分钟
可以使用JavaScript中的Date对象获取当前时间,然后格式化成指定的样式。修改后的代码如下:
<label for="date">指定时间:</label>
<input type="text" value="2023-01-02 16:00" name="" id="date"><br/>
<script>
// 获取当前时间
var now = new Date();
// 格式化时间为指定样式
var year = now.getFullYear();
var month = now.getMonth() + 1;
var day = now.getDate();
var hour = now.getHours();
var minute = now.getMinutes();
if (month < 10) month = '0' + month;
if (day < 10) day = '0' + day;
if (hour < 10) hour = '0' + hour;
if (minute < 10) minute = '0' + minute;
var current_time = year + '-' + month + '-' + day + ' ' + hour + ':' + minute;
// 将当前时间赋值给指定时间输入框
document.getElementById('date').value = current_time;
</script>

修改为获取当前时间的代码,当前时间精确度为分钟" title="可以将上述代码中 指定时间(样式为 年-月-日 时:分)
修改为获取当前时间的代码,当前时间精确度为分钟" loading="lazy">
原文地址: http://www.cveoy.top/t/topic/tKz 著作权归作者所有。请勿转载和采集!