getFormattedTime function

String getFormattedTime(
  1. DateTime? dateTime
)

Formats a DateTime object into a string of the format HH:mm:ss:SSS.

If the input is null, it returns "00:00:00".

Parameters:

  • dateTime (DateTime?): The date and time to format.

Returns:

  • String: The formatted time string.

Implementation

String getFormattedTime(DateTime? dateTime) {
  if (null == dateTime) {
    return '00:00:00';
  }
  return '${dateTime.hour.toString().padLeft(2, '0')}:${dateTime.minute.toString().padLeft(2, '0')}:${dateTime.second.toString().padLeft(2, '0')}:${dateTime.millisecond}';
}