javascript倒计时代码
其实就是用两个时间戳相减,余数转换为日期,就是所剩的年月日时分秒,不过年份-1970
$scope.timerID = null;
$scope.timerRunning = false;
$scope.showtime = function() {
if ($scope.data === undefined || $scope.data.auction_time_end === undefined) {
return;
}
Today = new Date();
var diffs = $scope.data.auction_time_end - Math.round(new Date().getTime()/1000);
if (diffs < 0) {
$("#spanLeft").html('0年, 0月, 0天, 0小时, 0分, 0秒');
return;
}
var newDate = new Date(diffs * 1000);
var year = newDate.getFullYear() - 1970;
var month = newDate.getMonth();
var date = newDate.getDate();
var hour = newDate.getHours();
var minutes = newDate.getMinutes();
var seconds = newDate.getSeconds();
s=year+'年, '+month+'月, '+date+'天, '+hour+'小时, '+minutes+'分, '+seconds+'秒';
$("#spanLeft").html(s);
$scope.timerID = setTimeout($scope.showtime, 1000);
$scope.timerRunning = true;
}
$scope.timerID = null;
$scope.timerRunning = false;
$scope.stopclock = function() {
if($scope.timerRunning)
clearTimeout($scope.timerID);
$scope.timerRunning = false;
}
$scope.startclock = function() {
$scope.stopclock();
$scope.showtime();
}
$scope.startclock()
javascript倒计时代码的更多相关文章
- javascript 倒计时代码
<script language="javascript" type="text/javascript"> var interval = 1000; ...
- javascript倒计时代码及倒计时弹窗
在前端开发中,难免会用到倒计时.如做的双十一活动,在距活动开始的半个月前需要做些宣传工作,需要告知用户优惠活动什么时候开始.这个时候就要用到倒计时,如在整站的某个页面提醒用户活动什么时候开始等.而在活 ...
- JS倒计时代码
第一种:精确到秒的javascript倒计时代码 HTML代码: <form name="form1"> <div align="center" ...
- Javascript倒计时页面跳转
在js中实现页面定时跳转我们要使用setInterval或setTimeOut函数,还可以使用页面的meta实现. 例1: <script type="text/javascript& ...
- JS倒计时 代码
JS倒计时 代码 <div> <span id="KSD">3</span>天 <span id="KSH">1 ...
- 活动倒计时代码(精确到毫秒)jquery插件
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Javascript特效代码大全(420个)(转)
转载自:Javascript特效代码大全(420个) 收集资料,以便使用+面试+学习 ├ Cookie脚本 ├ 随访问次数变提示 ├ 集成Cookies ├ 使窗口仅弹出一次 ├ 签名提示程序 ├ ...
- javascript两行代码按指定格式输出日期时间
javascript两行代码按指定格式输出日期时间,具体看代码: function date2str(x,y) { var z ={y:x.getFullYear(),M:x.getMonth()+1 ...
- javascript常用代码大全
http://caibaojian.com/288.html 原文链接 jquery选中radio //如果之前有选中的,则把选中radio取消掉 $("#tj_cat .pro_ca ...
随机推荐
- Jsonp 前后端交互操作
今天,因为项目的需要,研究了一下JSONP,特在此记录一下 ,希望可以帮助那些有疑惑的朋友们,本人也是刚学,高手略过即可. 关于Jsonp的定义就不说了,网上一片,大家可以自己查询.我就在此直接进入正 ...
- Eclipse和intellij idea 快捷键对比
Eclipse和intellij idea 快捷键对比
- SpringMVC数据绑定全面示例(复杂对象,数组等)
点击链接查询原文 http://www.xdemo.org/springmvc-data-bind/ 已经使用SpringMVC开发了几个项目,平时也有不少朋友问我数据怎么传输,怎么绑定之类的话题,今 ...
- Checkbox框全选操作,form表单提交与jquery ajax提交两种处理方式
//1.jquery ajax<script type="text/javascript"> $(function(){ var basePath = $(" ...
- git安装及使用
一.安装 1.从http://code.google.com/p/msysgit/下载Git-1.8.4-preview20130916.exe,并安装. 2.新建git目录,右键选择Git Bash ...
- PKU 1458 Common Subsequence(最长公共子序列,dp,简单)
题目 同:ZJU 1733,HDU 1159 #include <stdio.h> #include <string.h> #include <algorithm> ...
- HDU 1829 A Bug's Life(种类并查集)
思路:见代码吧. #include <stdio.h> #include <string.h> #include <set> #include <vector ...
- 暑假集训单切赛第一场 CF 191A Dynasty Puzzles
题意不说了,看原题吧,思路见代码: #include <iostream> #include <stdio.h> #include <string.h> #incl ...
- ZOJ 3757 Alice and Bob and Cue Sports(模拟)
题目链接 题意 : 玩台球.Alice 和 Bob,一共可以进行m次,Alice 先打.有一个白球和n个标有不同标号的球,称目标球为当前在桌子上的除了白球以外的数值最小的球,默认白球的标号为0.如果白 ...
- 关于C#中timer类
·关于C#中timer类 在C#里关于定时器类就有3个 1.定义在System.Windows.Forms里 2.定义在System.Threading.Timer类里 3.定义在System.Tim ...