js秒数转换时分秒方法
今天写一个东西的时候 发现给出的是秒数。实在找不到直接的工具去转换。
就去网上找了个转换方法(有现成的就不写了,以后再简化下代码)。
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秒数转换时分秒方法的更多相关文章
- PHP——秒数转换为时分秒
前言 通讯记录需要用到的一个方法,就是将秒转为时分秒 方法 PHP有内置的方法,直接用即可,不过这个只是24小时以内.对于通讯录来说是够用了~ 示例 $v = 30; gmdate('H:i:s', ...
- JavaScript--将秒数换算成时分秒
getTime() 返回距 1970 年 1 月 1 日之间的毫秒数 new Date(dateString) 定义 Date 对象的一种方式 <!DOCTYPE html> <h ...
- js将秒数换算成时分秒
转载自:http://jingyan.baidu.com/article/375c8e19a0413925f2a229d2.html <script language="javascr ...
- java将秒数转换为时分秒格式
/** * 转换时间格式为xx小时xx分xx秒 * @param second xxxxx */ public String changeTimeFormat(String second) { Int ...
- js将秒数转换为时分秒格式
function secondToTimeStr(t) { if (!t) return; if (t < 60) return "00:" + ((i = t) < ...
- PHP 秒数 转时分秒 函数
function secondsToHour($seconds){ if(intval($seconds) < 60) $tt ="00时00分".sprintf(" ...
- PHP 把秒数转为时分秒格式
PHP函数 1.gmdate $seconds = 174940;$hours = intval($seconds/); $time1 = $hours."小时".gmdate(' ...
- php 把秒数转换为时长(h:i:s格式)
/** * 把秒数转换为时分秒的格式 * @param Int $times 时间,单位 秒 * @return String */ function secToTime($times){ $resu ...
- PHP函数gmstrftime()将秒数转换成天时分秒
http://yangjunwei.com/a/930.html PHP函数gmstrftime()将秒数转换成天时分秒 一个应用场景需要用到倒计时的时分秒,比如新浪微博授权有效期剩余: 7天16 ...
随机推荐
- 利用VHDL读写file文件
library ieee; use std.textio.all; use ieee.std_logic_textio.all; use ieee.std_logic_1164 ...
- 调bug时候应该提高思维深度(多问二十个为什么)
版权声明:本文为博主原创文章,未经博主允许不得转载. (一)关于思维深度 读书时 有的人做一份卷子有一份卷子的收获 有的人做100张卷子只有一份卷子的收获 写代码时 有的人调一个Bug可以收获多方面的 ...
- 【Windows 8 Store App】学习:目录
原文http://www.cnblogs.com/java-koma/archive/2013/05/22/3093302.html 写在前面:我之前从事java开发,对MS的一整套东西还没入门哈,难 ...
- mybatis.generator.configurationFile
mybatis.generator.configurationFile 有一个更好的配置方法,可以不用在generateConfig.xml里面写死驱动的地址:如果你的mybatis连接也是在pom. ...
- poj2070简单题
#include <stdio.h> #include <stdlib.h> int main() { float sped; int wei,sth; while(scanf ...
- Let the Balloon Rise(map)
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- Windows7中搭建Android x86_64及armv8-a操作步骤
1. 从https://developer.android.com/tools/sdk/ndk/index.html 下载android-ndk-r10d-windows-x86_64. ...
- Dearmweaver CS6 如何添加emmet 插件
一.关于emmet插件 已经接触前端工具的小伙伴们早听说过这个插件的鼎鼎大名了吧,emmet可以说是前端工程师的利器,就连老牌dreamweaver 都可以支持,我们怎么好意思拒绝这个好东西呢? 有 ...
- SQL练习之不破坏应用程序现有查询的修改模式
当我还是一个菜鸟的时候,当然现在也是,当我的软件需求发生变化时,并且数据库设计同样要求发生变化,我通常会放弃原有的代码(或者对原有的代码进行大改),先在我知道了两个不破坏应用程序现有查询的修改模式,下 ...
- NET项目反编译+VS解决方案整理流程
net项目反编译 工具:De4Dot + IL SPY和Reflector结合使用 项目:vs10+创建解决方案,每个类库尽量按照dll名来命名,方便整合,新建web项目先把aspx等文件拷贝进去,注 ...