• 时间转换相关的JS


      1 //当前时间戳转换时间(年月日时分秒)
      2 function computingTime() {
      3     var now = new Date();
      4     var year = now.getFullYear();
      5     var month = now.getMonth();
      6     var date = now.getDate();
      7     var hour = now.getHours();
      8     var min = now.getMinutes();
      9     var sec = now.getSeconds();
     10     month = month + 1;
     11     if (month < 10) month = "0" + month;
     12     if (date < 10) date = "0" + date;
     13     if (hour < 10) hour = "0" + hour;
     14     if (min < 10) minu = "0" + min;
     15     if (sec < 10) sec = "0" + sec;
     16     var time = "";
     17     time = year + "年" + month + "月" + date + "日" + " " + hour + ":" + min + ":" + sec + " ";
     18     return time;
     19 }
     20 
     21 //时间戳转换时间(时:分:秒)
     22 function getDateTime(date) {
     23     var now;
     24     if (date.length == 10) {
     25         now = new Date(parseInt(date) * 1000);
     26     } else if (date.length == 13) {
     27         now = new Date(parseInt(date));
     28     } else {
     29         now = new Date();
     30     }
     31     var year = now.getFullYear();
     32     var month = now.getMonth();
     33     var date = now.getDate();
     34     var hour = now.getHours();
     35     var min = now.getMinutes();
     36     var sec = now.getSeconds();
     37     month = month + 1;
     38     if (month < 10) month = "0" + month;
     39     if (date < 10) date = "0" + date;
     40     if (hour < 10) hour = "0" + hour;
     41     if (min < 10) minu = "0" + min;
     42     if (sec < 10) sec = "0" + sec;
     43     var time = "";
     44     time = hour + ":" + min + ":" + sec + " ";
     45     return time;
     46 }
     47 //时间长短转换 秒变成时分 
     48 function formatSeconds(value) {
     49     var theTime = parseInt(value);// 需要转换的时间秒
     50     var theTime1 = 0;// 分
     51     var theTime2 = 0;// 小时
     52     var theTime3 = 0;// 天
     53     if (theTime > 60) {
     54         theTime1 = parseInt(theTime / 60);
     55         theTime = parseInt(theTime % 60);
     56         if (theTime1 > 60) {
     57             theTime2 = parseInt(theTime1 / 60);
     58             theTime1 = parseInt(theTime1 % 60);
     59             if (theTime2 > 24) {
     60                 //大于24小时
     61                 theTime3 = parseInt(theTime2 / 24);
     62                 theTime2 = parseInt(theTime2 % 24);
     63             }
     64         }
     65     }
     66     var result = '';
     67     if (theTime > 0) {
     68         result = "" + parseInt(theTime) + "秒";
     69     }
     70     if (theTime1 > 0) {
     71         result = "" + parseInt(theTime1) + "分" + result;
     72     }
     73     if (theTime2 > 0) {
     74         result = "" + parseInt(theTime2) + "小时" + result;
     75     }
     76     if (theTime3 > 0) {
     77         result = "" + parseInt(theTime3) + "天" + result;
     78     }
     79     return result;
     80 }
     81 //@*当前时间*@
     82 var slidint;
     83 function newTimer() {
     84     var today;
     85     today = new Date();
     86     var str = today.toLocaleDateString();
     87     str += "  " + week();
     88     str += "  " + today.toLocaleTimeString();
     89     var o = document.getElementById("DateTime");
     90     o.innerHTML = str;
     91     slidint = setTimeout(newTimer, 1000);
     92 }
     93 
     94 function week() {
     95     var d, day, x, s = " ";
     96     var x = new Array("星期日", "星期一", "星期二");
     97     var x = x.concat("星期三", "星期四", "星期五");
     98     var x = x.concat("星期六");
     99     d = new Date();
    100     day = d.getDay();
    101     return (s += x[day]);
    102 }
    103 
    104     function GetDateFormat(str) {
    105         var now = new Date(parseInt(str.substr(6, 13)));
    106         var year = now.getFullYear();
    107         var month = now.getMonth();
    108         var date = now.getDate();
    109         var hour = now.getHours();
    110         var min = now.getMinutes();
    111         var sec = now.getSeconds();
    112         month = month + 1;
    113         if (month < 10) month = "0" + month;
    114         if (date < 10) date = "0" + date;
    115         if (hour < 10) hour = "0" + hour;
    116         if (min < 10) minu = "0" + min;
    117         if (sec < 10) sec = "0" + sec;
    118         var time = "";
    119         time = year + "年" + month + "月" + date + "日" + " " + hour + ":" + min + ":" + sec + " ";
    120         return time;
    121         //return new Date(parseInt(str.substr(6, 13))).toLocaleDateString();
    122     }
  • 相关阅读:
    sysbench压测Oracle
    linux使用FIO测试磁盘的iops
    oracle 列授权相关测试
    11G、12C安装结束需要做的一些操作
    Oracle 12C R2 on Linux 7.X 单实例静默安装文档
    auto_create_partition
    关于使用索引的一些经验
    转:【Python3网络爬虫开发实战】 requests基本用法
    转:http协议学习系列(响应头---Response Headers)
    关于建立老猿Python研学群的公告
  • 原文地址:https://www.cnblogs.com/sdya233/p/14313213.html
Copyright © 2020-2023  润新知