其他分享
首页 > 其他分享> > JS随笔

JS随笔

作者:互联网

 

1.通过时间戳的方式将 2022-07-23 09:29:56 的时间戳转化成  2022-07-23 00:00:00 的时间戳 (把时分秒去掉,输出为时间戳)

//获取要优化时间戳
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))

 

标签:00,console,JS,month,date,var,随笔,day
来源: https://www.cnblogs.com/itqinls/p/16512185.html