1. 时间戳 格式化为 时分秒(00:00:00)

     /**
* 时间秒数格式化
* @param s 时间戳(单位:秒)
* @returns {*} 格式化后的时分秒
*/
var sec_to_time = function(s) {
var t;
if(s > -1){
var hour = Math.floor(s/3600);
var min = Math.floor(s/60) % 60;
var sec = s % 60;
if(hour < 10) {
t = '0'+ hour + ":";
} else {
t = hour + ":";
} if(min < 10){t += "0";}
t += min + ":";
if(sec < 10){t += "0";}
t += sec.toFixed(2);
}
return t;
}

2. 时分秒(00:00:00) 转为 时间戳

    /**
* 时间转为秒
* @param time 时间(00:00:00)
* @returns {string} 时间戳(单位:秒)
*/
var time_to_sec = function (time) {
var s = ''; var hour = time.split(':')[0];
var min = time.split(':')[1];
var sec = time.split(':')[2]; s = Number(hour*3600) + Number(min*60) + Number(sec); return s;
};

3. 年月日时分秒(2014.06.18  08:03:04)时间戳

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

js 时分秒与秒数的转换的更多相关文章

  1. python时间时分秒与秒数的互相转换

    受到Unix时间戳的启发,我发现时间转成秒数后会非常好处理,在程序当中不再是以字符串的形式处理,不管时间的加减还是获取随机的时间点都变得非常方便, 如果有需要,也很容易转换成需要的时间格式. 一:时间 ...

  2. js 时分秒转化为秒

    var time = '00:02:10'; var hour = time.split(':')[0]; var min = time.split(':')[1]; var sec = time.s ...

  3. js实现页面的秒数倒计时

    <button name="vcode_mail" class="btn btn-default" type="button" id= ...

  4. python练习-(秒转时分秒,时分秒转秒)-对比linux中文件的上次更改时间跟当前时间相差多久。

    具体代码如下> import paramiko,re,datetime,time ssh=paramiko.SSHClient() ssh.set_missing_host_key_policy ...

  5. JS 时分秒验证

  6. js timestamp 转换 date 和 将秒数整理为时分秒格式

    // 获得的后台json 时间格式转化 例如:1520305366000  转化为XXXX-XX-XX类似这种 function timeStamp2String(time){ var datetim ...

  7. js秒数转换时分秒方法

    今天写一个东西的时候 发现给出的是秒数.实在找不到直接的工具去转换. 就去网上找了个转换方法(有现成的就不写了,以后再简化下代码). function formatSeconds(value) { v ...

  8. PHP 将秒数转换成时分秒

    将秒数转换成时分秒,PHP提供了一个函数gmstrftime,不过该函数仅限于24小时内的秒数转换.对于超过24小时的秒数,我们应该怎么让其显示出来呢,例如 34:02:02 $seconds = 3 ...

  9. PHP函数gmstrftime()将秒数转换成天时分秒

    http://yangjunwei.com/a/930.html PHP函数gmstrftime()将秒数转换成天时分秒   一个应用场景需要用到倒计时的时分秒,比如新浪微博授权有效期剩余: 7天16 ...

随机推荐

  1. ZABBIX 4.0 LTS 部署

    1. 环境说明 关于zabbix的详细使用可以参考之前的3.0 版本,该文档仅记录zabbix 4.0 编译安装过程!ZABBIX 3.0 从入门到精通(zabbix使用详解) : https://w ...

  2. Docker中部署Mysql5.7和DbAdmin的docker-compose.yml

    一.简述 本文讲Docker通过docker-compose.yml部署Mysql5.7和dbAdmin的方法. 二.文件 1.docker-compose.yml内容如下: version: ' s ...

  3. API 'variant.getJavaCompiler()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()'

    WARNING: API 'variant.getJavaCompiler()' is obsolete and has been replaced with 'variant.getJavaComp ...

  4. 批量备份数据库脚本(PowerShell版)

    开始 昨天备份一个数据库拿来测试,发现备份后的文件非常大.后来去检查下使用的备份脚本,原来之前的备份脚本没有压缩功能. 现把之前的备份脚本修改下,支持压缩备份,和支持仅复制备份(CopyOnly). ...

  5. CentOS 7.4安装nodejs & nginx & pm2

    一.安装nodejs1.查看操作系统信息 uname -a cat /etc/centos-release 2.安装wget yum install wget -y3.安装nodejs 1.下载 wg ...

  6. UBANTU zongjie

    1.fatal error: openssl/aes.h: No such file or directory 要在Debian.Ubuntu或者其他衍生版上安装OpenSSL: $ sudo apt ...

  7. python conv2d scipy卷积运算

    scipy的signal模块经常用于信号处理,卷积.傅里叶变换.各种滤波.差值算法等. *两个一维信号卷积 >>> import numpy as np >>> x ...

  8. NetBeans使用Consolas中文乱码的解决

    1.进入jdk安装目录下/jre/lib文件夹,找到fontconfig.properties.src,拷贝为 fontconfig.properties ,修改此文件. 找到: sequence.m ...

  9. HTTPS和SSL握手过程(转载)

    https介绍 HTTPS = HTTP + 一组对称.非对称和基于证书的加密技术 HTTPS是最常见的HTTP安全版本.它得到了很广泛的应用,所有主要的商业浏览器和服务器都提供HTTPS.HTTPS ...

  10. 看雪CTF第十题

    __int64 sub_140006F50() { __int64 v0; // r8@1 __int64 v1; // r9@1 signed __int64 len; // rax@1 __int ...