addHours method

DateTime addHours(
  1. int amount
)

Adds a certain amount of hours to this date and returns a new DateTime instance.

Example:

DateTime currentDate = DateTime(2022, 1, 8, 12, 0);
DateTime futureDate = currentDate.addHours(3);
print(futureDate);  // 2022-01-08 15:00:00.000

The addHours method creates a new DateTime instance by adding the specified number of hours to the original date. The date components (year, month, day) remain unchanged.

Implementation

DateTime addHours(int amount) => DateTime(
      year,
      month,
      day,
      hour + amount,
      minute,
      second,
      millisecond,
      microsecond,
    );