Javascript时间以及格式化秒
var now = new Date();
timer = $.timer(timeout, function () {
var sec_num = Math.ceil((now.getTime() - startTime.getTime()) / 1000);
showPaperTimer(now, sec_num);
if (sec_num % 60 == 0) {
}
});
function showPaperTimer(now, sec_num) {
var nowStr = now.getFullYear() + '-';
nowStr += now.getMonth() + 1 + '-';
nowStr += now.getDate() + ' ';
nowStr += now.getHours() + ':';
nowStr += now.getMinutes() + ':';
nowStr += now.getSeconds();
var hours = Math.floor(sec_num / 3600);
var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
var seconds = sec_num - (hours * 3600) - (minutes * 60);
if (hours < 10) { hours = "0" + hours; }
if (minutes < 10) { minutes = "0" + minutes; }
if (seconds < 10) { seconds = "0" + seconds; }
var time0 = hours + ':' + minutes + ':' + seconds;
$("#times").html("当前时间:" + str + ",已耗时:" + time0);
}
其中,$.timer是一个Jq时钟,来自于http://plugins.jquery.com/timer/,其常用操作有:
var timeout = 1000;
var timer;
$("input[name=start]").click(function() {
$("#console").append("<span style=\"color: #0F0\">Timer started.</span<br />");
timer = $.timer(timeout, function() {
$("#console").append("Timer completed.<br />");
});
});
$("input[name=stop]").click(function() {
if(timer.stop()) {
$("#console").append("<span style=\"color: #F00\">Timer stopped.</span<br />");
}
});
$("input[name=pause]").click(function() {
if(timer.pause()) {
$("#console").append("<span style=\"color: #FF0\">Timer paused.</span<br />");
}
});
$("input[name=resume]").click(function() {
if(timer.resume()) {
$("#console").append("<span style=\"color: #F00\">Timer resumed.</span<br />");
}
});
$("input[name=reset]").click(function() {
timer.stop();
timeout = prompt("Reset timeout too:", 500);
timer.reset(timeout);
$("#console").append("<span style=\"color: #00F\">Timer reset.</span<br />");
});
Javascript时间以及格式化秒的更多相关文章
- JavaScript 对时间日期格式化
JavaScript 对时间日期格式化 // 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位 ...
- 【转载】vue.js实现格式化时间并每秒更新显示功能示例
引用:https://www.jb51.net/article/143351.htm 这篇文章主要介绍了vue.js实现格式化时间并每秒更新显示功能,结合实例形式分析了vue.js时间格式化显示与基于 ...
- javascript之input获取的时间减1秒&&t时间恢复
将输入得到的时间减少1秒:20:00:00 ——— 19:59:59 方法一:普通时间转换 endDateMap(date){ var h = new Date(date).getHours ...
- 第一百零四节,JavaScript时间与日期
JavaScript时间与日期 学习要点: 1.Date类型 2.通用的方法 3.格式化方法 4.组件方法 ECMAScript提供了Date类型来处理时间和日期.Date类型内置一系列获取和设置日期 ...
- JavaScript 时间与日期处理实战:你肯定被坑过
本部分的知识图谱请参考编程语言知识图谱-时间与日期. 本文JavaScript 时间与日期处理实战:你肯定被坑过从属于笔者的Web 前端入门与最佳实践中 JavaScript 入门与最佳实践系列文章. ...
- javascript 时间操作
javascript时间函数 javascript提供了Date对象来进行时间和日期的计算.Date对象有多种构造函数: 1.dateObj=new Date() //当前时间 2.dateObj=n ...
- python中时间日期格式化符号
python中时间日期格式化符号: import time print(time.strftime('%Y%H%M%S', time.localtime())) 运行结果: 2016092308 %y ...
- javascript 的Date 格式化, 模仿shell中date命令的格式
原文:javascript 的Date 格式化, 模仿shell中date命令的格式 shell 中显示当前的日期 [root@localhost]$ date '+%Y-%m-%d %H:%M:%S ...
- Java如何格式化秒数?
在Java中,如何格式化秒数? 此示例使用SimpleDateFormat类的SimpleDateFormat('ss')构造函数和sdf.format(date)方法格式化秒数. package c ...
随机推荐
- 【Java】 foreach对数组赋值问题
今天写代码时发现了如下问题: public class Test { public static void main(String[] args) { int[] arr= new int[5]; f ...
- Spring Boot 教程demo
https://github.com/ityouknow/spring-boot-examples
- 15:链表中倒数第K个节点
/** * 面试题15:链表中倒数第K个节点 * 输入一个链表,输出该链表中倒数第k个结点. */ public class _15_linked_K { public static void mai ...
- HDU - 1022 Train Problem I STL 压栈
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- spring websocket集群问题的简单记录
目录 前言 解决方案 代码示例 前言 最近公司里遇到一个问题,在集群中一些websocket的消息丢失了. 产生问题的原理很简单,发送消息的服务和接收者连接的服务不是同一个服务. 解决方案 用中间件( ...
- Python如何将RGB图像转换为Pytho灰度图像?
我正尝试使用matplotlib读取RGB图像并将其转换为灰度.在matlab中,我使用这个: 1 img = rgb2gray(imread('image.png')); 在matplotlib t ...
- Git 入门使用
Git是什么? Git是一个开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目. Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制 ...
- SQLSERVER2014集群实战——IP引发的坑
在之前的帖子里有提到过,为了避免IP变更带来的一系列问题,采取了不改变IP的策略.原以为,只要SQLSERVER的群集IP保持与之前单机部署的IP一致,就基本上不会有问题.然而实际永远比预想的更复杂. ...
- MyBatis之MyBatis环境搭建
MyBatis之MyBatis环境搭建 一.MyBatis开发环境搭建 1.引入Jar包 ①MyBatis mybatis-3.4.1.jar ant-1.9.6.jar ant-launcher-1 ...
- 【POJ】1840:Eqs【哈希表】
Eqs Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 18299 Accepted: 8933 Description ...