标签: countdown

C#倒计时计时器跳过时间

我在C#中有这个

private void counter_Tick(object sender, EventArgs e)
    {
        Time.Text = String.Format("{0:000}", Hour) + ":" + String.Format("{0:00}", Minute) + ":" + String.Format("{0:00}", Second);
        if (Second != 00)
        {
            Second = Second - 1;
        }
        else if (Minute != 00)
        {
            Minute = Minute - 1;
            Second = 59;
        }
        else if (Hour != 00)
        {
            Hour = Hour - 1;
            Minute = 59;
        }
        else
        {
            counter.Stop();
            Time.ForeColor = Color.Red;
        }
    }
Run Code Online (Sandbox Code Playgroud)

哪个可以工作,但是当它增加到零下一个小时添加到分钟时,它从00分钟变为58分钟而不是59分钟

例如.

From: 001:00:00
To:   000:58:59
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法让倒数计时器在点击000:00:00时做某事?

c# string timer countdown countdowntimer

0
推荐指数
1
解决办法
1526
查看次数

向这个 javascript 倒计时脚本添加前导零?

我正在使用以下倒计时脚本,效果很好,但我不知道如何为数字添加前导零(例如,它显示 09 而不是 9。)有人可以帮我吗?这是当前的脚本:

function countDown(id, end, cur){
        this.container = document.getElementById(id);
        this.endDate = new Date(end);
        this.curDate = new Date(cur);


var context = this;

var formatResults = function(day, hour, minute, second){
    var displayString = [
                '<div class="stat statBig">',day,'</div>',
                '<div class="stat statBig">',hour,'</div>',
                '<div class="stat statBig">',minute,'</div>',
                '<div class="stat statBig">',second,'</div>'
    ];
    return displayString.join("");
}

var update = function(){
    context.curDate.setSeconds(context.curDate.getSeconds()+1);

    var timediff = (context.endDate-context.curDate)/1000; 

    // Check if timer expired:
    if (timediff<0){ 
        return context.container.innerHTML = formatResults(0,0,0,0);
    }

    var oneMinute=60; //minute unit in seconds
    var oneHour=60*60; //hour …
Run Code Online (Sandbox Code Playgroud)

javascript countdown

0
推荐指数
1
解决办法
3623
查看次数

没有seq或jot的shell倒计时

我正在尝试制作倒数计时器脚本,该脚本需要几秒钟$1,然后倒计时到零,显示当前剩余的秒数.

问题是,我在一个没有的嵌入式盒子上做这个,seq或者jot我知道可以生成我的数字列表的两个工具.

这是我在普通(非嵌入式)系统上工作的脚本:

#!/bin/sh

for i in $(/usr/bin/jot ${1:-10} ${1:-10} 1); do
    printf "\r%s " "$i"
    sleep 1
done

echo ""
Run Code Online (Sandbox Code Playgroud)

这适用于FreeBSD.如果我在Linux机器上,我可以用以下代码替换for:

for i in $(/usr/bin/seq ${1:-10} -1 1); do
Run Code Online (Sandbox Code Playgroud)

为了同样的效果.

但如果我没有jotOR,我该怎么办seq

shell countdown

0
推荐指数
1
解决办法
3029
查看次数

为什么我的时间间隔得到负值?

我不知道发生了什么.我试图通过比较日期来制作一个有效的计时器.当我启动计时器时,它有时会工作,然后随机停止,有时它只返回timeInterval的值.当时间间隔为负时,它似乎只能正常工作.这是我的方法:

-(IBAction)startTimer:(id)sender{
    if (timer == nil) {
        [startButton setTitle:@"Start" forState:UIControlStateNormal];
        timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerAction:) userInfo:nil repeats:YES];
        date = [NSDate dateWithTimeIntervalSinceNow:testTask.timeInterval]; //instance variable
    } else {
        [startButton setTitle:@"Stop" forState:UIControlStateNormal];
        [timer invalidate];
        timer = nil;
    }

}
-(void)timerAction:(NSTimer *)t
{
    NSDate *currentDate = [NSDate date];
    NSTimeInterval updatedTimeInterval = [date timeIntervalSinceDate:currentDate];
    if (updatedTimeInterval > 0){
        if (self.timer)
        {
            [self timerExpired];
            [self.timer invalidate];
            self.timer = nil;
        }
    }
    else
    {
        testTask.timeInterval = updatedTimeInterval;
        NSLog(@"%.2f", testTask.timeInterval);
        NSError *error;
        if (![self.context save:&error]) {
            NSLog(@"couldn't …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c nstimer countdown ios

0
推荐指数
1
解决办法
1776
查看次数

倒数HH:MM:SS在Jquery

我想要倒数计时器的格式,hh:mm:ss所以我使用这个代码它将秒转换成所需的格式,但当我倒计时它显示我NaN.你能告诉我我做错了吗这是代码

<div id="timer"></div>
Run Code Online (Sandbox Code Playgroud)

JS

String.prototype.toHHMMSS = function () {
    var sec_num = parseInt(this, 10); // don't forget the second parm
    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 …
Run Code Online (Sandbox Code Playgroud)

javascript jquery countdown

0
推荐指数
1
解决办法
4040
查看次数

TimeSpan倒数计时器

我正在尝试通过以下方式在我的应用程序中显示倒计时:

private TimeSpan ts = new TimeSpan()


ts = ts.Subtract(TimeSpan.FromSeconds(1));
label4.Text = ts.ToString(@"hh\:mm\:ss");
Run Code Online (Sandbox Code Playgroud)

但是,它不显示倒计时,但实际上会增加时间。如果我移除@"hh\:mm\:ss"零件,那么我会在数秒内倒数,但不是真正的倒数。它所-1, -2, -3,要做的就是在秒之前添加一个减号,所以它确实如此...我希望它在10 to 0 so -9, -8, -7,等时说出来...

如何才能以的形式进行真正的倒计时hh:mm:ss

c# timer countdown countdowntimer

0
推荐指数
1
解决办法
4280
查看次数

Python Count Up&Down循环

我如何简单地将此循环转换为从1到100计数并显示数字?我最近开始编码。当倒数时,它可以正常工作,但我不知道如何使它从1 -100开始

例:

count = 100
while count > 0 :
    print(count)
    count = count - 1
Run Code Online (Sandbox Code Playgroud)

python counter loops countdown

0
推荐指数
2
解决办法
3万
查看次数

CountDown在swift中使用NSTimer

我还在快速学习,我正在尝试设计一个应用程序,在一个部分我将这个游戏计时器设置为7分钟(将添加弄清楚如何让客户稍后更改),现在它是7 :00,我添加了2个按钮,开始,暂停.我想让Start,启动countDown直到00:00,然后我打算添加一条弹出消息说时间到了!

代码到目前为止:

import UIKit

class ViewController: UIViewController {
@IBOutlet var countDown: UILabel!

var counter = 60
var timer = NSTimer()

func update() {

    if counter > 0 {
        countDown.text = String(counter--)
    }

}

@IBAction func start(sender: UIButton) {

    timer = NSTimer.scheduledTimerWithTimeInterval(0.4, target: self, selector: #selector(ViewController.update), userInfo: nil, repeats: true)

}

@IBAction func pause(sender: UIButton) {
     // timer.invalidate() stops the whole thing...
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
Run Code Online (Sandbox Code Playgroud)

}

然而,应用程序继续崩溃...我不知道如何使计时器超过60秒,如何表示它.

nstimer countdown swift

0
推荐指数
1
解决办法
761
查看次数

不使用函数的 Vanilla Javascript 中的倒数计时器

我有一个项目需要做一个倒数计时器,但是没有功能可以使用。我知道这可以通过 setInterval 来完成,但是,我发现的大多数文档都显示了一个结合使用的函数。W3schools 有一个很好的例子,但是,它使用了一个函数。我知道我会怎么做

我已经写了一些代码,并且能够显示分钟和秒,但是,不能让它真正倒计时。有没有办法在没有函数的情况下做到这一点?

const timeSpan = document.getElementById('timer');

// Get Time Now
var timeMinutes = 10;
var currentTime = Date.parse(new Date());
var deadline = new Date(currentTime + timeMinutes * 60 * 1000);
var distance = deadline - currentTime;
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);

timeSpan.innerHTML = minutes + 's' + seconds;
Run Code Online (Sandbox Code Playgroud)

这显示了分钟和秒,但没有 setInterval 或 setTimeOut 它不会像普通的倒数计时器那样倒计时。对于该项目,它需要从 10 分钟开始倒计时,最后提醒用户已过期,他们需要刷新页面。

javascript countdown

0
推荐指数
1
解决办法
1817
查看次数

如何在 HH:MM:SS(小时:分钟:秒)中显示倒数计时器

如何从我制作的 XMl android 中倒计时 'HH: mm: ss',当 24 小时内没有交互时,则无法再次进行交易或无法再次访问

此代码是倒数计时器的设计 UI。

倒计时器

<androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/constrainlayout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="18dp"
        android:layout_marginEnd="20dp"
        android:layout_marginRight="20dp"
        android:background="@drawable/bg_color_orange"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/app_bar">

        <TextView
            android:id="@+id/textView_Title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="18dp"
            android:text="Please make a payment Immediatelly"
            android:textColor="@android:color/black"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/constrainlayout" />

        <TextView
            android:id="@+id/textView_TimeCountDown"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="18dp"
            android:text="13 Hour: 59 Minute: 21 Second"
            android:textColor="@android:color/black"
            android:textSize="22sp"
            app:layout_constraintEnd_toEndOf="@+id/textView_Title"
            app:layout_constraintStart_toStartOf="@+id/textView_Title"
            app:layout_constraintTop_toBottomOf="@+id/textView_Title" />

        <TextView
            android:id="@+id/textView_Day"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="18dp"
            android:layout_marginBottom="18dp"
            android:text="(Before Thursday, 16 January 2020, 13:33 WIB)"
            android:textColor="@android:color/black"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="@+id/textView_Title"
            app:layout_constraintStart_toStartOf="@+id/textView_Title"
            app:layout_constraintTop_toBottomOf="@id/textView_TimeCountDown" />

    </androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

该代码将像这样显示

倒计时器

java android countdown countdowntimer kotlin

0
推荐指数
1
解决办法
4270
查看次数

如何修正 Ruby 倒计时器?

import time

def countdown(time_sec):
  while time_sec:
    mins, secs = divmod(time_sec, 60)
    timeformat = "{:02d}:{:02d}".format(mins, secs)
    print(timeformat, end='\r')
    time.sleep(1)
    time_sec -= 1

  print("Time ended.")
Run Code Online (Sandbox Code Playgroud)

您在上面看到的这段 Python 代码运行顺利,并从给定的 开始倒计时time_sec。此代码还每秒清洁屏幕。我想编写在 Ruby 中工作完全相同的代码。

#timer.rb(Ruby codes) here
def countdown time_sec
    
    while time_sec
        mins, secs = time_sec.divmod(60)[0], time_sec.divmod(60)[1]
        timeformat = "%02d:%02d" % [mins, secs]
        puts "#{timeformat}\r"
        sleep(1)
        time_sec -= 1
    end
    
    puts "Time is ended."
end 
Run Code Online (Sandbox Code Playgroud)

您在上面看到的这段 Ruby 代码以错误的方式工作。首先,秒数被依次打印。但我想像上面的 Python 代码一样更新单行。其次,当运行此 Ruby 代码并达到倒计时时00:00,它会继续从 开始倒计时-01:59。我该如何更正此代码?

ruby time timer carriage-return countdown

0
推荐指数
1
解决办法
259
查看次数

给此倒数计时器加0

我终于设法使我的24小时非日期可靠的倒数计时器。这样做的目的是,每当有人访问该网站时,倒计时就会开始。问题在于,当任何单位(小时,分钟,秒)达到个位数时,值将按原样显示它们而不是标准时间格式(应按9分钟而不是09分钟显示)。我如何实现一个条件,如果值<= 9会在其前面加上0?

var count = 86400;
var counter = setInterval(timer, 1000); //1000 will  run it every 1 second

function timer() {
  count = count - 1;
  if (count == -1) {
    clearInterval(counter);
    return;
  }

  var seconds = count % 60;
  var minutes = Math.floor(count / 60);
  var hours = Math.floor(minutes / 60);
  minutes %= 60;
  hours %= 60;

  document.getElementById("timer").innerHTML = hours + ":" + minutes + ":" + seconds; // watch for spelling
}
Run Code Online (Sandbox Code Playgroud)
 <span id='timer'></span>
Run Code Online (Sandbox Code Playgroud)

javascript timer countdown

-2
推荐指数
1
解决办法
1626
查看次数