JS随笔
1.通过时间戳的方式将 2022-07-23 09:29:56 的时间戳转化成 2022-07-23 00:00:00 的时间戳 (把时分秒去掉,输出为时间戳)
// 将当天时间戳(s)+86400s 当天时间戳(ms)+86400000 ms
//获取要优化时间戳
var timestamp = record.EWB_DATE;
//随便减去一个整时时间戳(2016-01-01 00:00:00) var temp = timestamp-1451577600000;
//取余 var aaa = temp%86400000;
//减去当天的余数就变成整数了 record.EWB_DATE = timestamp-aaa;
2.js将时间戳转化为时间格式
function RiQi(sj) { var date = new Date(); var year = date.getFullYear(); var month = date.getMonth(); var day = date.getDay(); var hours = date.getHours(); var minutes = date.getMinutes(); var seconds = date.getSeconds(); if (month < 10) { month = "0" + month; } if (day < 10) { day = "0" + day; } var sqlTime = year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds; console.log(date); console.log(sqlTime); } console.log(RiQi(1658539796))