Skip to content

Instantly share code, notes, and snippets.

@makmac213
Created April 16, 2025 07:52
Show Gist options
  • Save makmac213/be48b84c460745a4a26fe951741b54d5 to your computer and use it in GitHub Desktop.
Save makmac213/be48b84c460745a4a26fe951741b54d5 to your computer and use it in GitHub Desktop.
// This will check if the device is using 24-hour or 12-hour time settings.
// Experienced an error where client is in a different region and they can not
// select a time. It turns out we have different time format.
bool is24HourFormat = MediaQuery.of(context).alwaysUse24HourFormat;
String timeString = value.format(context);
if (is24HourFormat) {
reportTimeController.text = timeString;
} else {
DateTime timeDateTime = DateFormat("hh:mm a").parse(timeString);
reportTimeController.text = DateFormat("HH:mm").format(timeDateTime);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment