formatTimestamp static method

String formatTimestamp(
  1. DateTime timestamp, {
  2. bool includeTime = true,
})

Formats a timestamp for display.

timestamp is the timestamp to format. includeTime determines whether to include the time component. Returns a formatted timestamp string.

Implementation

static String formatTimestamp(
  DateTime timestamp, {
  bool includeTime = true,
}) {
  final date = '${timestamp.year}-${_padZero(timestamp.month)}-${_padZero(timestamp.day)}';

  if (!includeTime) {
    return date;
  }

  final time =
      '${_padZero(timestamp.hour)}:${_padZero(timestamp.minute)}:${_padZero(timestamp.second)}';

  return '$date $time';
}