首页 > 解决方案 > Flutter - 用我想醒来的小时确定睡觉的时间

问题描述

我是 Dart 和 Flutter 的新手,正在寻求帮助。我正在尝试这样做:

- 用户在库比蒂诺日期选择器中选择一个小时和分钟(这是他想在早上醒来的时间)

-我想确定他需要入睡的确切时间才能有 7 小时的良好睡眠。

(此功能有效,但我不知道如何将分钟添加到小时,然后确定正确的计算)

void Bed(int Heure, int Minute) {

    if (Heure - Cycle <= 0) {
      result = Heure - Cycle + 24;

    } else {

      result = Heure - Cycle;
    }
  }

谢谢您的帮助 !

标签: datetimeflutterdart

解决方案


我只会在几分钟内计算。所以拿你的 hours*60 ,你只用分钟计算,然后最后转换回小时。

  double total = 140; //Your total time converted to minutes

  double mins = total % 60; //your minutes

  double hrs = (total - mins) / 60; // your hours

  print(mins);
  print(hrs);

推荐阅读