飞镖:显示直到下一次的时间

时间:2018-12-20 02:50:06

标签: dart countdowntimer

如何显示倒数计时的持续时间直到下一个警报

代码:

List<PictureBox> logos = new List<PictureBox>();   
private List<PictureBox> Insert_Logo()
{
    PictureBox pic1 = new PictureBox();
    Image image = Image.FromFile("D:\\Project\\Mini-Game\\Mini-Game\\bin\\Image\\Renault.bmp");
    pic1.Image = image;

    PictureBox pic2 = new PictureBox();
    Image a = Image.FromFile("D:\\Project\\Mini-Game\\Mini-Game\\bin\\Image\\vw.bmp");
    pic2.Size = new Size(a.Width, a.Height);
    pic2.Image = a;

    PictureBox pic3 = new PictureBox();
    Image s = Image.FromFile("D:\\Project\\Mini-Game\\Mini-Game\\bin\\Image\\alfa.bmp");
    pic3.Size = new Size(s.Width, s.Height);
    pic3.Image = s;

    logos.Add(pic1);
    logos.Add(pic2);
    logos.Add(pic3);
    return logos;
}

private void PictuteBox_CLICK(object sender, EventArgs e)
{

    logos = Insert_Logo();
    //The Insert_Logo function returns a list of pictureboxes.
    int randomnumber;
    randomnumber = random.Next(0, logos.Count);
    //Replace Picturebox with the name of the picturebox you want to show the image in
    Picturebox.Image = logos[randomnumber].Image;
    logos.RemoveAt(randomnumber); 
}

但是时差是错误的,并且没有动画。还有如何确保时差在第二天的同一天和第二天的时间起作用,即现在是12月1日2:30 PM,我想在12月2日6:15 AM得到时差。

1 个答案:

答案 0 :(得分:0)

之所以无效,是因为TimeOfDay代表一天中的某个时间,而与该日期或时区无关。时间仅用小时和分钟表示。

如果您希望倒计时跨越多天,则必须使用DateTime,并且在格式化结果字符串之前,时差评估需要一些数学运算,例如:

String nextTime(DateTime nextAlarmTime) {
  List<int> ctime = [0, 0, 0, 0];
  DateTime now = DateTime.now();
  int diff = nextAlarmTime.difference(now).inSeconds;
  ctime[0] = diff ~/ (24 * 60 * 60); // days
  diff -= ctime[0] * 24 * 60 * 60;

  ctime[1] = diff ~/ (60 * 60); // hours
  diff -= ctime[1] * 60 * 60;

  ctime[2] = diff ~/ 60; // minutes
  ctime[3] = diff - ctime[2] * 60;  // seconds

  return ctime.map((val) => val.toString().padLeft(2, '0')).join(':');
}