0

Whenever I open the page which has my DateTime function on it, the default time that it shows is the current time, which then I have to change. How do I change it so that the default time is 2 hours ahead of the current time? This is not a timezone issue, I have looked at that.

DateTime _time = DateTime.now();

_selectTime() async {
    DatePicker.showDateTimePicker(
      context,
      showTitleActions: true,
      onConfirm: (dateTime) {
        if (dateTime != null) {
          _time = dateTime;
          setState(() {});
        }
      },
    );
  }

I would like the default time to be 2 hours ahead of the current time. So the current time is 07:30, I would like it to rather be 09:30.

  • Possible duplicate of [flutter timeofday calculations](https://stackoverflow.com/questions/53015124/flutter-timeofday-calculations) – franiis Jul 05 '19 at 06:00

1 Answers1

0

Do you mean something like this?

DateTime _time = DateTime.now();

_selectTime() async {
    _time = _time.add(new Duration(hours: 2));
    DatePicker.showDateTimePicker(
      context,
      showTitleActions: true,
      onConfirm: (dateTime) {
        if (dateTime != null) {
          _time = dateTime;
          setState(() {});
        }
      },
    );
  }
Arthur S.
  • 482
  • 2
  • 8
  • 25