minus method

  1. @useResult
DateTime minus({
  1. int years = 0,
  2. int months = 0,
  3. int days = 0,
  4. int hours = 0,
  5. int minutes = 0,
  6. int seconds = 0,
  7. int milliseconds = 0,
  8. int microseconds = 0,
})

Returns a copy of this with the units of time subtracted.

This function subtracts the conceptual units of time like -.

// DST occurs at 2023-03-12 02:00
// https://www.timeanddate.com/time/change/usa/detroit?year=2023

// Assume the current timezone is `America/Detroit`.
final datetime = DateTime(2023, 3, 13);

datetime.minus(days: 1);              // 2023-03-12 00:00
datetime.subtract(Duration(days: 1)); // 2023-03-11 23:00

Implementation

@useResult DateTime minus({
  int years = 0,
  int months = 0,
  int days = 0,
  int hours = 0,
  int minutes = 0,
  int seconds = 0,
  int milliseconds = 0,
  int microseconds = 0,
}) => copyWith(
  year: year - years,
  month: month - months,
  day: day - days,
  hour: hour - hours,
  minute: minute - minutes,
  second: second - seconds,
  millisecond: millisecond - milliseconds,
  microsecond: microsecond - microseconds,
);