combineDateAndTime function

DateTime combineDateAndTime(
  1. Date date,
  2. Time time
)

Combines a Date and Time into a single DateTime instance. The resulting DateTime will be in UTC. Note that Date and Time instances are always in UTC internally, as they convert any input to UTC during construction.

This is useful when you need to combine separate date and time components into a single point in time.

Example:

final date = Date.today();  // Creates UTC date
final time = Time.now();    // Creates UTC time
final dateTime = combineDateAndTime(date, time);  // Returns UTC DateTime

Implementation

DateTime combineDateAndTime(Date date, Time time) => DateTime.utc(
      date.year,
      date.month,
      date.day,
      time.hour,
      time.minute,
      time.second,
    );