用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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年03月25日 10时12分50秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
【物联网实训项目】------(六)家庭智慧安防系统之智能监控
2019-04-26
【物联网实训项目】------(七)家庭智慧安防系统之人脸验证
2019-04-26
日常琐事(一)
2019-04-26
数据结构----绪论
2019-04-26
篇章二线性表---基础知识
2019-04-26
篇章二线性表---常见操作
2021-06-29
回溯法关于图
2021-06-29
04 Python数据类型之元组、集合
2021-06-29
05 Python之条件与循环
2021-06-29
06 Python之函数调用与定义
2021-06-29
07 Python之Numpy库
2021-06-29
08 Python之Pandas库选择查看、选择
2021-06-29
09 Python之Pandas库之数据处理与规整
2021-06-29
10 Python之Matplotlib库
2021-06-29
11 Python总结之股票数据量化分析
2021-06-29
12 Python总结之蒙特卡洛模拟
2021-06-29
13 Python总结之估值
2021-06-29
14 Python总结之风险管理
2021-06-29
15 Python总结之数据分析与挖掘
2021-06-29
16 Python总结之舆情时间序列可视化
2021-06-29