您的位置:首页 > 编程语言 > C语言/C++

/*做一个2:00的倒计时,但是失败了,问题在哪。C语言。*/

2014-08-01 19:06 429 查看

/*做一个2:00的倒计时,但是失败了,问题在哪。C语言。*/

/*做一个2:00的倒计时,但是失败了,问题在哪。C语言。*/
	int a = 2, b = 60, c;
	while (a >= 0)
	{
		if (b == 60)
			c = 0; 
		else 
			c = b;
		//system("cls"); 
		if (c > 9)
			printf_s("%d:%d.", a, c);
		else 
			printf_s("%d:0%d.", a, c);
		Sleep(1000);
		if (--b == 0)
			b = 60;
		if (b == 59)
			a--;
	}



int a = 2, b = 60, c;
	while (a >= 0)
	{
		c = (b == 60) ? 0 : b;
		system("cls");
		printf_s((c > 9) ? "%d:%d " : "%d:0%d ", a, c);
		Sleep(1000);
		if (!--b) b = 60;
		if (b == 59) a--;
	}


c#

int a = 2, b = 60, c;
            while (a >= 0)
            {
                c = (b == 60) ? 0 : b;
                Console.WriteLine((c > 9) ? "{0}:{1} " : "{0}:{1} ", a, c);
                Thread.Sleep(1000);
                if (--b == 0) b = 60;
                if (b == 59) a--;
            }


vb

Dim shijian As DateTime = DateTime.Parse("0:5:0")
        Dim miao As Integer = shijian.Second
        Dim a = 5 * 60
        Do While a > 0
            miao -= 1
            a -= 1
            Console.WriteLine(shijian.AddSeconds(miao).ToLongTimeString)
            System.Threading.Thread.Sleep(1000)
        Loop

用C#的timer控件 做一个 倒计时的 东东~ 怎么搞来的。怎么给Timer设置 值啊

public Form1()
        {
            InitializeComponent();
            System.Timers.Timer 定时 = new System.Timers.Timer(1000);
            定时.Elapsed += new System.Timers.ElapsedEventHandler(计时事件);
            定时.Enabled = true;
            Label 显示 = new Label();
            显示.Name = "显示";
            显示.Parent = this;
            /*之下设置指定时间和秒*/
            时间 = DateTime.Parse("14:46");
            减 = 时间.Second + 4;

        }
        DateTime 时间 = DateTime.Now;
        int 减 = DateTime.Now.Second;

        void 计时事件(object sender, EventArgs e)
        {
            this.Invoke(new Action(() => { this.Controls["显示"].Text = 时间.AddSeconds(减--).TimeOfDay.ToString(); }));
        }

vb:

Dim 计数 As Integer = 0
    Dim 设置时间 As DateTime = DateTime.Parse("0:5:0")

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        设置时间 = DateTime.Parse("0:1:0")
        TextBox1.Text = 设置时间.ToLongTimeString
        时钟.Start()
    End Sub
    Private Sub 时钟_Tick(sender As Object, e As EventArgs) Handles 时钟.Tick
        计数 -= 1
        TextBox1.Text = 设置时间.AddSeconds(计数).ToLongTimeString
        If DateTime.Parse(TextBox1.Text).Minute = 0 And DateTime.Parse(TextBox1.Text).Second <= 10 Then Console.Beep()
        If DateTime.Parse(TextBox1.Text).Minute = 0 And DateTime.Parse(TextBox1.Text).Second = 0 Then 时钟.Stop()
    End Sub


VB:设定日期范围倒计时

Dim 时间范围 = DateTime.Parse("2015-2-1") - DateTime.Now
        文本框.Text = 时间范围.Days.ToString + "天" + 时间范围.Hours.ToString + ":" + 时间范围.Minutes.ToString + ":" + 时间范围.Seconds.ToString
        设置时间 = DateTime.Parse(时间范围.ToString.Split(".")(1))
        时钟.Start()
    Private Sub 时钟_Tick(sender As Object, e As EventArgs) Handles 时钟.Tick
        计数 -= 1
        Dim 倒计时 = 文本框.Text.Split("天"), 倒计天 As Integer = Integer.Parse(倒计时(0))
        文本框.Text = 倒计时(0) + "天" + 设置时间.AddSeconds(计数).ToLongTimeString
        If DateTime.Parse(倒计时(1)).Minute = 0 And DateTime.Parse(倒计时(1)).Second <= 10 Then Console.Beep()
        If DateTime.Parse(倒计时(1)).Hour = 0 And DateTime.Parse(倒计时(1)).Minute = 0 And DateTime.Parse(倒计时(1)).Second = 0 Then
            倒计天 -= 1
            文本框.Text = 倒计天.ToString + "天" + 设置时间.AddSeconds(计数).ToLongTimeString
        End If
        If DateTime.Parse(倒计时(1)).Hour = 0 And DateTime.Parse(倒计时(1)).Minute = 0 And DateTime.Parse(倒计时(1)).Second = 0 And 倒计天 = 0 Then 时钟.Stop()
    End Sub





内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐