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()

  • 相关阅读:
    专题页移动端适配实例
    iconfont字体图标使用方法
    HBuilder常用快捷键
    tab
    tab-qq
    微信小程序之购物车功能
    margin塌陷
    weui-wxss-master下载地址
    python_vlc 播放http流
    go学习笔记-简述
  • 原文地址:https://www.cnblogs.com/yuanxiaoping_21cn_com/p/4888374.html
Copyright © 2011-2022 走看看