getDateTime function

String getDateTime({
  1. required String date,
  2. String? format,
  3. bool toApi = true,
  4. bool isUTC = true,
  5. String locale = 'en_US',
})

Implementation

String getDateTime({
  required String date,
  String? format,
  bool toApi = true,
  bool isUTC = true,
  String locale = 'en_US',
}) {
  try {
    return DateFormat(
      format ?? DateFormats.dateTime.format,
      toApi ? 'en_US' : locale,
    ).format(
      isUTC
          ? DateTime.tryParse(date)?.toLocal() ?? DateTime.now()
          : DateTime.tryParse(date) ?? DateTime.now(),
    );
  } catch (e) {
    log(e.toString());
    return "";
  }
}