电商商城定制开发电商商城定制开发中国标准时间-格式: Sat Apr 09 2022 08:00:00 GMT+0800 (中国标准时间)
标准时间-格式: 2022-04-09
时间戳-格式: 1649462400000
一、中国标准时间和标准时间相互转换
1、中国标准时间 => 标准时间
// 中国标准时间 转换成 年月日function getSimpleDate(date) { var y = date.getFullYear(); var m = date.getMonth() + 1; m = m < 10 ? ('0' + m) : m; var d = date.getDate(); d = d < 10 ? ('0' + d) : d; var h = date.getHours(); var minute = date.getMinutes(); minute = minute < 10 ? ('0' + minute) : minute; var s = date.getSeconds(); s = s < 10 ? '0' + s : s; return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + s;}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
2、标准时间 => 中国标准时间
var s=new Date(stime).getTime();
- 1
二、中国标准时间和相互转换
1、中国标准时间 => 时间戳
new Date() // Wed Jan 12 2022 11:14:50 GMT+0800 (中国标准时间)new Date().getTime() // 1641957294080
- 1
- 2
2、时间戳 => 中国标准时间
function getSimpleDate(date) { let dd = new Date(date) // 时间戳转化成中国标准时间格式 return dd }
- 1
- 2
- 3
- 4
三、标准时间 和 时间戳 相互转换
1、标准时间 => 时间戳
function getSimpleDate(date) { let stamp = new Date(currentDate).getTime() // 年月日转化成时间戳 //let preDate = new Date(currentDate).getTime() - (24 * 60 * 60 * 1000) // 前一天时间戳 //let afterDate = new Date(currentDate).getTime() + (24 * 60 * 60 * 1000) // 后一天时间戳 return stamp}
- 1
- 2
- 3
- 4
- 5
- 6
2、时间戳 => 标准时间
function getSimpleDate(date) { let dd = new Date(date).getTime() // 时间戳转化成标准时间 return dd }
- 1
- 2
- 3
- 4