2016年10月15日 星期六

2016/10/14 倒數計時

c#











using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        DateTime dtNext;
        TimeSpan RemainderTime;
        public Form1()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            textBox1.Text = DateTime.Now.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer2.Start();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            timer2.Stop();
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            RemainderTime = dtNext-DateTime.Now;

            string diffHour = Convert.ToString(RemainderTime.Hours);
            string diffMin = Convert.ToString(RemainderTime.Minutes);
            string diffSec = Convert.ToString(RemainderTime.Seconds);
            label1.Text = "還有" + diffHour + " 時 " + diffMin + " 分 " + diffSec + " 秒 ";

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            dtNext = DateTime.Now.AddMinutes(2);

        }
    }
}
=======================================================================
unity
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;

public class NewBehaviourScript : MonoBehaviour {

// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
        DateTime Now = DateTime.Now;
        Text mytxt = GameObject.Find("Canvas/Panel/Text").GetComponent<Text>();
        mytxt.text = ""+Now;
    }
}


沒有留言:

張貼留言