getDate function

String getDate(
  1. DateTime date
)

Implementation

String getDate(DateTime date) {
  return DateTime.now().difference(date).inMinutes < 60
      ? '${DateTime.now().difference(date).inMinutes} minutes ago'
      : DateTime.now().difference(date).inHours < 24
          ? '${DateTime.now().difference(date).inHours} hours ago'
          : DateTime.now().difference(date).inDays < 30
              ? '${DateTime.now().difference(date).inDays} days ago'
              : DateTime.now().difference(date).inDays < 365
                  ? '${DateTime.now().difference(date).inDays / 30} months ago'
                  : '${DateTime.now().difference(date).inDays / 365} years ago';
}