美文网首页
时间戳转年月日

时间戳转年月日

作者: 小北呀_ | 来源:发表于2020-05-26 17:50 被阅读0次

                    let date =new Date();//时间戳为10位需*1000,时间戳为13位的话不需乘1000
                    let Y = date.getFullYear();
                    let M = (date.getMonth() +1 <10 ?'0' + (date.getMonth() +1) : date.getMonth() +1);
                    let D = date.getDate() < 10 ? ('0' + date.getDate()) : date.getDate();
                    let  h = date.getHours() < 10 ? ('0' + date.getHours()) : date.getHours();
                    let m = date.getMinutes() < 10 ? ('0' + date.getMinutes()) : date.getMinutes();
                    let s = date.getSeconds() < 10 ? ('0' + date.getSeconds()) : date.getSeconds();
                    let left = Y + '-' + M + '-' + D
                    let right = h + ':' + m + ':' + s

相关文章

网友评论

      本文标题:时间戳转年月日

      本文链接:https://www.haomeiwen.com/subject/hqvvahtx.html