zoukankan      html  css  js  c++  java
  • js timestamp 转换 date 和 将秒数整理为时分秒格式

    // 获得的后台json 时间格式转化 例如:1520305366000  转化为XXXX-XX-XX类似这种

     1 function timeStamp2String(time){
     2 var datetime = new Date();
     3 datetime.setTime(time);
     4 var year = datetime.getFullYear();
     5 var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
     6 var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
     7 var hour = datetime.getHours()< 10 ? "0" + datetime.getHours() : datetime.getHours();
     8 var minute = datetime.getMinutes()< 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
     9 var second = datetime.getSeconds()< 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
    10 return year + "-" + month + "-" + date+“-”+hours+“-”+minutes+“-”+seconds;
    11 }

    //js转化获取的秒数 , 为06:23,用于时钟、音视频播放。

     1 function formatSeconds(value) {
     2 var theTime = parseInt(value);//
     3 var theTime1 = 0;//
     4 var theTime2 = 0;// 小时
     5 if (theTime > 60) {
     6 theTime1 = parseInt(theTime / 60);
     7 theTime = parseInt(theTime % 60);
     8 if (theTime1 > 60) {
     9 theTime2 = parseInt(theTime1 / 60);
    10 theTime1 = parseInt(theTime1 % 60);
    11 }
    12 }
    13 
    14 var result = "" + parseInt(theTime);//
    15 if (10 > theTime > 0) {
    16 result = "0" + parseInt(theTime);//
    17 } else {
    18 result = "" + parseInt(theTime);//
    19 }
    20 
    21 if (10 > theTime1 > 0) {
    22 result = "0" + parseInt(theTime1) + ":" + result;//分,不足两位数,首位补充0,
    23 } else {
    24 result = "" + parseInt(theTime1) + ":" + result;//
    25 }
    26 if (theTime2 > 0) {
    27 result = "" + parseInt(theTime2) + ":" + result;//
    28 }
    29 return result;
    30 
    31 }
  • 相关阅读:
    1648 最大和
    poj2243
    Codevs 2307[SDOI2009]HH的项链
    2597 团伙
    一个JavaWeb项目中使用的部分技术
    Oracle 11g 学习3——表空间操作
    iOS实现抽屉效果
    用shell脚本实现linux系统上wifi模式(STA和soft AP)的转换
    Codeforces Round #243 (Div. 1)——Sereja and Two Sequences
    站点选择配色诀窍
  • 原文地址:https://www.cnblogs.com/liqiong-web/p/8549368.html
Copyright © 2011-2022 走看看