时间戳转具体时间

时间戳转具体时间

1.在util中新建time.js
// 时间戳转换为日期
function time(time){
    
    
  var date = new Date(time);
  var Y = date.getFullYear() + '-'; 
  var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
  var h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + ':';
  var m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes());
  var s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());
  return time = Y + M + D + h + m;
}
module.exports = {
    
    
  time: time
}
2.在具体的页面中引入
var wxbarcode=require('../../utils/index.js')
3.使用
console.log('44',times.time(parseInt(时间戳的值))
4.获取当前的时间戳
(new Date()).valueOf()
5.三天以后
(new Date()).valueOf()+86400000

猜你喜欢

转载自blog.csdn.net/qq_48164590/article/details/130218801