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. Outlook Error: The Delegates settings were not saved correctly. Cannot activate send-on-behalf-of list.

    When user want to set Delegates for a user of a mailbox, the user meet below error. Step 1: Step 2: ...

  2. Centos PHP+Apache执行exec()等Linux脚本权限设置的详细步骤

    1. 查看一下你的Apache的执行用户是谁: lsof -i:80         运行之后的结果为: 从图中我们可以清楚的看到,httpd(也就是Apache)的执行用户为:exec_shell( ...

  3. Win7 32位下cocos2dx android开发调试环境

    1.使用环境 win7 32位 + vs2010 2.软件准备(下方绿色文字带链接) cocos2dx-v2.2.2 jdk7 android sdk android ndk adt bundle a ...

  4. Spring-boot之 rabbitmq

    今天学习了下spring-boot接入rabbitmq. windows下的安装:https://www.cnblogs.com/ericli-ericli/p/5902270.html 使用博客:h ...

  5. linux服务查看

    (1)#service servicename status比如查看防火墙:#service iptables status (2)#chkconfig --list |grep 服务名 比如查看te ...

  6. centos7环境安装ElasticSearch

    操作系统: Centos7 .64位 ========================================= 查看系统版本和系统位数: [root@localhost /]# cat /e ...

  7. Dubbo 在maven项目中的应用

    首先我们来看一下dubbo的架构: 所以通过此图,我们看到就是服务的提供者将服务注册到注册中心,服务的消费者从注册中心获取服务,monitor监控服务的调用. 关于dubbo的使用,我们举个简单的例子 ...

  8. Linux操作系统配置Go语言编程环境

    之前一直在windows下写Go,现在工作环境切换至Linux下,因此写下此文,记录安装Go环境的过程. 操作系统:CentOS7.5 一.安装步骤 1,下载Go语言安装包 yum install g ...

  9. springboot-thymeleaf

    Thymeleaf 是一个跟 Velocity.FreeMarker 类似的模板引擎,它可以完全替代 JSP .相较与其他的模板引擎,它有如下三个极吸引人的特点: Thymeleaf 在有网络和无网络 ...

  10. MySQL 5.7.14安装说明,解决服务无法启动

    http://jingyan.baidu.com/article/f54ae2fc0affca1e92b84999.html http://www.myexception.cn/mysql/51431 ...