javascript倒计时代码
2015-10-17 21:53
489 查看
其实就是用两个时间戳相减,余数转换为日期,就是所剩的年月日时分秒,不过年份-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()
$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()
相关文章推荐
- js屏蔽右键代码
- javascript之闭包
- Github API JSON
- Github API 库的JSON文件格式
- JavaScript 的性能优化:加载和执行
- js获取复选框的值
- JavaScript作用域以及闭包(二)
- Github API 库的JSON文件格式
- JavaScript事件绑定
- javascript之作用域链
- 理解javascript的闭包,原型,和匿名函数及IIFE
- Javascript中this关键字详解
- javascript 案例(二)表格操作(下)
- js中的一个方法怎么将数据主动传给另一个方法
- JSON.parse()和JSON.stringify()
- JSP生成WORD文档,EXCEL文档及PDF文档的方法
- javascript 实现输入框只能输入数字
- jsp之c标签用法实例分析
- javascript 案例(二)表格的操作(上)
- clamp.js用法初窥