今天写一个东西的时候 发现给出的是秒数。实在找不到直接的工具去转换。

就去网上找了个转换方法(有现成的就不写了,以后再简化下代码)。

 function formatSeconds(value) {
var theTime = parseInt(value);// 秒
var theTime1 = 0;// 分
var theTime2 = 0;// 小时
// alert(theTime);
if(theTime > 60) {
theTime1 = parseInt(theTime/60);
theTime = parseInt(theTime%60);
// alert(theTime1+"-"+theTime);
if(theTime1 > 60) {
theTime2 = parseInt(theTime1/60);
theTime1 = parseInt(theTime1%60);
}
}
var result = ""+parseInt(theTime)+"秒";
if(theTime1 > 0) {
result = ""+parseInt(theTime1)+"分"+result;
}
if(theTime2 > 0) {
result = ""+parseInt(theTime2)+"小时"+result;
}
return result;
}

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

  1. PHP——秒数转换为时分秒

    前言 通讯记录需要用到的一个方法,就是将秒转为时分秒 方法 PHP有内置的方法,直接用即可,不过这个只是24小时以内.对于通讯录来说是够用了~ 示例 $v = 30; gmdate('H:i:s', ...

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

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

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

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

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

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

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

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

  6. PHP 秒数 转时分秒 函数

    function secondsToHour($seconds){ if(intval($seconds) < 60) $tt ="00时00分".sprintf(" ...

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

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

  8. php 把秒数转换为时长(h:i:s格式)

    /** * 把秒数转换为时分秒的格式 * @param Int $times 时间,单位 秒 * @return String */ function secToTime($times){ $resu ...

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

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

随机推荐

  1. linux开机自动挂载NTFS-WINDOWS分区

    1.安装ntfs-3g-2009.4.4.tgz 2.输入fdisk -l 看一下分区 由此可见:/dev/sda5,6,7 即是windows下的D,E,F盘(NTFS格式). 3.vim /etc ...

  2. RejexLib

    http://www.regexlib.com/ http://www.brics.dk/automaton/index.html http://code.google.com/p/automatap ...

  3. [LeetCode][Python]Regular Expression Matching

    # -*- coding: utf8 -*-'''https://oj.leetcode.com/problems/regular-expression-matching/ Implement reg ...

  4. jquery插件tab——小试牛刀

    <html> <head> <script type="text/javascript" src="http://ajax.googleap ...

  5. Phalcon 调试应用程序

    调试应用程序(Debugging Applications)¶ Phalcon中提供了提供了几种调试级别即通知,错误和异常. 异常类 Exception class 提供了发生错误时的一些经常使用的调 ...

  6. Web安全測试二步走

    Web安全測试时一个比較复杂的过程,软件測试人员能够在当中做一些简单的測试,例如以下: Web安全測试也应该遵循尽早測试的原则,在进行功能測试的时候(就应该运行以下的測试Checklist安全測试场景 ...

  7. xcode -饼状进度条

    界面搭建 创建一个画饼状的类  eatView 集成UIView #import "eatView.h" @implementation eatView // Only overr ...

  8. 关于ECMAScript6一些知识

    ECMAScript 是当前 JavaScript 语言规范的最新标准,一般称为 es6, 但是因为 该标准规范是在 2015年6月份发布的,所以也叫作 ECMAScript 2015 let 变量声 ...

  9. MYSQL知识点

    1.MYSQL为了可移植性,使用"--"做为注释,使用"/*!*/"表示可执行的注释.

  10. webpack和webpack-dev-server的区别

    第一: webpack只是构建 webpack-dev-server除了构建,还提供web服务   第二:webpack.config.json的路径参数 显然,entry都一样,因为都要知道需要构建 ...