isValidDatetimeUtc static method

bool isValidDatetimeUtc(
  1. String? str
)

Returns true if str parses to a UTC date/time.

Unlike DateTime.parse, an unparsable, null, or empty str returns false instead of throwing.

Implementation

static bool isValidDatetimeUtc(String? str) {
  if (str.isNullOrEmpty) return false;

  final dateTime = DateTime.tryParse(str!);
  return dateTime != null && dateTime.isUtc;
}