formatSimpleDateTime function

String formatSimpleDateTime(
  1. DateTime date
)

date가 오늘인지와 연도가 같은지에 따라 간결한 한국어 문자열을 만든다.

Implementation

String formatSimpleDateTime(DateTime date) {
  final now = DateTime.now();

  if (now.year != date.year) {
    return DateFormat("yyyy년 M월 d일").format(date);
  }

  if (now.month != date.month || now.day != date.day) {
    return DateFormat("M월 d일").format(date);
  }

  return DateFormat(
    "a h:mm",
  ).format(date).replaceAll('PM', '오후').replaceAll('AM', '오전');
}