// 获得的后台json 时间格式转化 例如:1520305366000  转化为XXXX-XX-XX类似这种
function timeStamp2String(time){
var datetime = new Date();
datetime.setTime(time);
var year = datetime.getFullYear();
var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
var hour = datetime.getHours()< 10 ? "0" + datetime.getHours() : datetime.getHours();
var minute = datetime.getMinutes()< 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
var second = datetime.getSeconds()< 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
return year + "-" + month + "-" + date+“-”+hours+“-”+minutes+“-”+seconds;
}

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

function formatSeconds(value) {
var theTime = parseInt(value);// 秒
var theTime1 = 0;// 分
var theTime2 = 0;// 小时
if (theTime > 60) {
theTime1 = parseInt(theTime / 60);
theTime = parseInt(theTime % 60);
if (theTime1 > 60) {
theTime2 = parseInt(theTime1 / 60);
theTime1 = parseInt(theTime1 % 60);
}
}
var result = "" + parseInt(theTime);//秒
if (10 > theTime > 0) {
result = "0" + parseInt(theTime);//秒
} else {
result = "" + parseInt(theTime);//秒
}
if (10 > theTime1 > 0) {
result = "0" + parseInt(theTime1) + ":" + result;//分,不足两位数,首位补充0,
} else {
result = "" + parseInt(theTime1) + ":" + result;//分
}
if (theTime2 > 0) {
result = "" + parseInt(theTime2) + ":" + result;//时
}
return result;
}

js timestamp 转换 date 和 将秒数整理为时分秒格式的更多相关文章

  1. C# 使用TimeSpan秒数转化为时分秒的写法

    1.TimeSpan的生成方法 // 参数: // ticks: // A time period expressed in 100-nanosecond units. public TimeSpan ...

  2. PHP 把秒数转为时分秒格式

    PHP函数 1.gmdate $seconds = 174940;$hours = intval($seconds/); $time1 = $hours."小时".gmdate(' ...

  3. 转换GMT秒数为日期时间格式-Delphi源码

    转换GMT秒数为日期时间格式-Delphi源码.收藏最近在写PE分析工具的时候,需要转换TimeDateStamp字段值为日期时间格式,这是Delphi的源码. //把GMT时间的秒数转换成日期时间格 ...

  4. Oracle 把秒转成时分秒格式(hh24:mm:ss);检测字符串是否是数字;字符串转换为数字

    不说废话,贴代码: CREATE OR REPLACE FUNCTION to_time(sec IN NUMBER) RETURN VARCHAR2 IS /*把秒转成时分秒格式 auth lzpo ...

  5. oracle timestamp转换date及date类型相减

    --timestamp转换为date(ts字段为timestamp类型) ; --timestamp转换为date(ts字段为timestamp类型) ; --date相减 )) FROM dual; ...

  6. js将秒数换算成时分秒

    转载自:http://jingyan.baidu.com/article/375c8e19a0413925f2a229d2.html <script language="javascr ...

  7. java将秒数转换为时分秒格式

    /** * 转换时间格式为xx小时xx分xx秒 * @param second xxxxx */ public String changeTimeFormat(String second) { Int ...

  8. JavaScript--将秒数换算成时分秒

    getTime()  返回距 1970 年 1 月 1 日之间的毫秒数 new Date(dateString) 定义 Date 对象的一种方式 <!DOCTYPE html> <h ...

  9. js将秒数转换为时分秒格式

    function secondToTimeStr(t) { if (!t) return; if (t < 60) return "00:" + ((i = t) < ...

随机推荐

  1. Python面试题之一:解密

    Python面试题之一: 说明:就是Python工程师面试题 一.字典转换与正则提取值 1:key与Value交换 a = {'a':1,'b':2} print({value:key for key ...

  2. linux查看80端口占用情况

    netstat -anltp|grep  80

  3. 第一天docker入门

    [01 入门] docker 最核心为三部分组成 镜像,仓库和容器 镜像:一个只读的模板 仓库:代码仓库,镜像的集合 容器:镜像的实例化进程 我们可以这样理解 容器就是一个沙箱,docker利用容器运 ...

  4. 2、shader基本语法、变量类型、shader的三种形式、subshader、fallback、Pass LOD、tags

    新建一个shader,名为MyShader1内容如下: 1._MainTex 为变量名 2.“Base (RGB)”表示在unity编辑面板中显示的名字,可以定义为中文 3.2D 表示变量的类型 4. ...

  5. python multiprocessing.Pool 中map、map_async、apply、apply_async的区别

    multiprocessing是python的多进程库,multiprocessing.dummy则是多线程的版本,使用都一样. 其中都有pool池的概念,进程池/线程池有共同的方法,其中方法对比如下 ...

  6. ASP.NET Core [3]:进入HttpContext的世界(笔记)

    原文链接:http://www.cnblogs.com/RainingNight/p/httpcontext-in-asp-net-core.html HttpContext是ASP.NET中的核心对 ...

  7. crontab-用于设置周期性被执行的指令

    一个很好用的工具. 参考文章: [入门] http://baike.baidu.com/view/1229061.htm [进阶] http://blog.csdn.net/tianlesoftwar ...

  8. 编译caffe遇到的问题

    1. failed to see hdf5.h https://askubuntu.com/questions/629654/building-caffe-failed-to-see-hdf5-h 2 ...

  9. Problem 1036 四塔问题

    Accept: 590    Submit: 1506Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description “汉诺 ...

  10. linux服务进程管理

    1.查看linux占用内存/CPU最多的进程 查使用内存最多的10个进程 ps -aux | sort -k4nr | head -n 10 或者top (然后按下M,注意大写) 查使用CPU最多的1 ...