本文主要和大家分享js时间戳转为正常时间格式的方法代码,希望能帮助到大家。
//js时间戳转为yyyy-mm-dd hh:mm:ss
function exchangetime(timestamp){
var str = "";
str += timestamp.getfullyear() + '-';
timestamp.getmonth() < 10 ? str += '0' + (timestamp.getmonth() + 1) + '-' : str += (timestamp.getmonth() + 1) + '-';
timestamp.getdate() < 10 ? str += '0' + timestamp.getdate() + ' ' : str += timestamp.getdate() + ' ';
timestamp.gethours() < 10 ? str += '0' + timestamp.gethours() + ':' : str += timestamp.gethours() + ':';
timestamp.getminutes() < 10 ? str += '0' + timestamp.getminutes() + ':' : str += timestamp.getminutes() + ':';
timestamp.getseconds() < 10 ? str += '0' + timestamp.getseconds(): str += timestamp.getseconds();
return str;
}
相关推荐:
js时间戳和普通时间相互转换方法代码
js时间戳如何转为时间格式
js时间戳格式化成日期格式的多种方法_javascript技巧
以上就是js时间戳转为正常时间格式的方法代码的详细内容。