• js将时间戳装换成日期格式


    13位时间戳改为yyyy-MM-dd HH-mm-ss 格式 
    目标时间戳:1516324500000

    formatDateTime (unix) { // 转换时间戳
                var date = new Date(unix)// 时间戳为10位需*1000,时间戳为13位的话不需乘1000
                var Y = date.getFullYear() + '-'
                var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
                var D = date.getDate() + ' '
                var h = date.getHours() + ':'
                var m = date.getMinutes() + ':'
                var s = date.getSeconds()
                return Y + M + D + h + m + s
            }




    //将时间戳改为yyyy-MM-dd HH-mm-ss function formatDateTime(unix) { var now = new Date(parseInt(unix) * 1); now = now.toLocaleString().replace(/年|月/g, "-").replace(/日/g, " "); if(now.indexOf("下午") > 0) { if (now.length == 18) { var temp1 = now.substring(0, now.indexOf("下午")); //2014/7/6 var temp2 = now.substring(now.indexOf("下午") + 2, now.length); // 5:17:43 var temp3 = temp2.substring(0, 1); // 5 var temp4 = parseInt(temp3); // 5 temp4 = 12 + temp4; // 17 var temp5 = temp4 + temp2.substring(1, temp2.length); // 17:17:43 now = temp1 + temp5; // 2014/7/6 17:17:43 now = now.replace("/", "-"); // 2014-7/6 17:17:43 now = now.replace("/", "-"); // 2014-7-6 17:17:43 }else { var temp1 = now.substring(0, now.indexOf("下午")); //2014/7/6 var temp2 = now.substring(now.indexOf("下午") + 2, now.length); // 5:17:43 var temp3 = temp2.substring(0, 2); // 5 if (temp3 == 12){ temp3 -= 12; } var temp4 = parseInt(temp3); // 5 temp4 = 12 + temp4; // 17 var temp5 = temp4 + temp2.substring(2, temp2.length); // 17:17:43 now = temp1 + temp5; // 2014/7/6 17:17:43 now = now.replace("/", "-"); // 2014-7/6 17:17:43 now = now.replace("/", "-"); // 2014-7-6 17:17:43 } }else { var temp1 = now.substring(0,now.indexOf("上午")); //2014/7/6 var temp2 = now.substring(now.indexOf("上午")+2,now.length); // 5:17:43 var temp3 = temp2.substring(0,1); // 5 var index = 1; var temp4 = parseInt(temp3); // 5 if(temp4 == 0 ) { // 00 temp4 = "0"+temp4; }else if(temp4 == 1) { // 10 11 12 index = 2; var tempIndex = temp2.substring(1,2); if(tempIndex != ":") { temp4 = temp4 + "" + tempIndex; }else { // 01 temp4 = "0"+temp4; } }else { // 02 03 ... 09 temp4 = "0"+temp4; } var temp5 = temp4 + temp2.substring(index,temp2.length); // 07:17:43 now = temp1 + temp5; // 2014/7/6 07:17:43 now = now.replace("/","-"); // 2014-7/6 07:17:43 now = now.replace("/","-"); // 2014-7-6 07:17:43 } return now; }; alert(formatDateTime(1516324500000));

      

  • 相关阅读:
    php操作redis报错Redis::__set_state(array( 'socket' => NULL, ))
    vue项目新部署ERROR Error: Cannot find module 'webpack/lib/rules/DescriptionDataMatcherRulePlugin'
    dubbo注册到 zookeeper + 使用apollo配置中心整合
    @ConfigurationProperties注解的使用
    centos下安装 clickhouse
    Linux脚本中使用特定JDK
    几种主流的分布式定时任务
    c++ 左值引用与右值引用
    H264文件读取帧数据
    网络丢包分析
  • 原文地址:https://www.cnblogs.com/taochengyong/p/9341877.html
Copyright © 2020-2023  润新知