用js将从后台得到的时间戳转换成日期
发布日期:2021-07-23 08:50:56 浏览次数:21 分类:技术文章

本文共 819 字,大约阅读时间需要 2 分钟。

 

转载  https://blog.csdn.net/qq_38052210/article/details/80277569

得到的时间戳:1526007949000;

处理:

var unixTimestamp = new Date(1526007949000);

commonTime = unixTimestamp.toLocaleString();
console.log(commonTime)

结果:2018/5/11 上午11:05:49

如果希望转换成自己需要的格式,需要从写一下toLocalString()方法;

Date.prototype.toLocaleString = function() {

return this.getFullYear() + "/" + (this.getMonth() + 1) + "/" + this.getDate() +"   "+ this.getHours() + ":" + this.getMinutes() + ":" + this.getSeconds();

};

结果:2018/5/11   11:5:49

Date.prototype.toLocaleString = function() {

return this.getFullYear() + "年" + (this.getMonth() + 1) + "月" + this.getDate() +"日"+" "+ this.getHours() + "时" + this.getMinutes() + "分" + this.getSeconds()+"秒";

};

结果:2018年5月11日 11时5分49秒

日期转换成时间戳

var date = new Date('2018-05-11 11:05:49');

console.log(date.getTime())

结果:1526007949000

转载地址:https://blog.csdn.net/namechenfl/article/details/84344965 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:js中常见的去重方式
下一篇:vscode全局搜失效解决方式

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年03月25日 10时12分50秒