<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<div id="times">这是内容</div>
</body>
<script>
var this_time='2021-09-01 00:00:00';
var this_stamp = new Date(this_time);
var last_stamp = this_stamp.getTime()-86400000;
var new_date=new Date(last_stamp);
var last_date = new_date.toLocaleDateString(last_stamp);
var current_stamp = document.getElementById('times').innerHTML=last_date;
//以下是个人的笔记,可省略
//指定时间或当天时间的0点时间戳
var this_time= '2021-02-02 00:00:00';
var this_stamp = new Date(this_time).getTime();
var current_stamp = new Date(new Date().toLocaleDateString()).getTime();
//获取当前时间戳
第一种方法:(这种方法只精确到秒)
var timestamp = Date.parse(new Date());
结果:1280977330000
第二种方法:
var timestamp = (new Date()).valueOf();
结果:1280977330748
第三种方法:
var timestamp=new Date().getTime();
结果:1280977330748
</script>
</html>