zoukankan      html  css  js  c++  java
  • 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()

  • 相关阅读:
    函数中this指向问题及函数不同方式的调用
    拷贝继承
    组合继承
    借用构造函数
    继承
    UVA-11054(扫描法)
    hihocoder-1347 小h的树上的朋友(lca+线段树)
    UVA-10391(字符串检索)
    UVA-10125(中途相遇法)
    UVA-10827(前缀和降维)
  • 原文地址:https://www.cnblogs.com/yuanxiaoping_21cn_com/p/4888374.html
Copyright © 2011-2022 走看看