js 时间日期与时间戳之间转换

时间:2022-05-30 06:00:40
 1 1.将时间(2017-08-10)转换时间戳
2 var startTime = '2017-08-10';
3 var startdate = new Date(Date.parse(startTime.replace(/-/g, "/")));
4 startdate = startdate.getTime() / 1000;
5 alert(startdate)
6
7 2.将时间(2017-08-10 10:15:30)转换时间戳
8 var startTime = '2017-08-10 10:15:30';
9 var startdate = new Date(Date.parse(startTime.replace(/-/g, "/")));
10 startdate = startdate.getTime() / 1000;
11 alert(startdate)
12
13 3.时间(2017/08/10)转换时间戳
14 var times = '2017/08/10';
15 var old = (new Date(times)).getTime()/1000;
16 alert(old);
17
18 4.时间(2017/08/10 15:15:30)转换时间戳
19 var times = '2017/08/10 15:15:30';
20 var old = (new Date(times)).getTime()/1000;
21 alert(old);