当前位置: 移动技术网 > IT编程>开发语言>Jquery > js转换时间戳-转换成 yyyy-MM-dd HH:mm:ss

js转换时间戳-转换成 yyyy-MM-dd HH:mm:ss

2019年04月05日  | 移动技术网IT编程  | 我要评论

比如:转换成 yyyy-mm-dd hh:mm:ss

//时间戳转换方法    date:时间戳数字
function formatdate(date) {
  var date = new date(date);
  var yy = date.getfullyear() + '-';
  var mm = (date.getmonth() + 1 < 10 ? '0' + (date.getmonth() + 1) : date.getmonth() + 1) + '-';
  var dd = (date.getdate() < 10 ? '0' + (date.getdate()) : date.getdate());
  var hh = (date.gethours() < 10 ? '0' + date.gethours() : date.gethours()) + ':';
  var mm = (date.getminutes() < 10 ? '0' + date.getminutes() : date.getminutes()) + ':';
  var ss = (date.getseconds() < 10 ? '0' + date.getseconds() : date.getseconds());
  return yy + mm + dd +" "+hh + mm + ss;
}

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网