// 动态生成时间
function showTime(){
nowtime=new Date();
year=nowtime.getFullYear();
month=nowtime.getMonth()+1;
date=nowtime.getDate();
time = nowtime.toLocaleTimeString()
// 处理格式
function conversionTime(time) {
var dayTime = time.substring(0, 2) // 当前time类型 ,上午和下午
var currentTime = time.substring(2, time.length) // 当前时间(只保留后面时间戳)
var timeList = currentTime.split(':') // 转化为数组
if (dayTime === '下午' && timeList[0].trim()!=='12') { // 对下午的时间进行操作
timeList[0] = Number(timeList[0]) + 12 // 第0个数组为当前小时数, + 12
currentTime = timeList.toString().replace(/,/g, ':') // 转化为标准时间格式 00:00:00
}
return currentTime
};
var nowTime = conversionTime(time);
var Ntime = year+"-"+month+"-"+date+" "+nowTime
$(".acceptanceTime").val(Ntime);
}
setInterval(showTime, 1000);
参考1:https://blog.csdn.net/ma18845639852/article/details/70339527
参考2:https://blog.csdn.net/mnhn456/article/details/78731852