Adrian Alejo
Adrian Alejo

Reputation: 91

How can I change the showDateTimePicker() into 12 hour format?

I want the time change into 12 hours format. Here's my code:

            TextButton(
            onPressed: () {
              FocusScope.of(context).unfocus();
              DatePicker.showDateTimePicker(
                context,
                showTitleActions: true,
                onConfirm: widget.onChangeDateSched,
                locale: LocaleType.en,
              );
            },

Upvotes: 0

Views: 526

Answers (3)

Jahidul Islam
Jahidul Islam

Reputation: 12595

you can try with this package flutter_datetime_picker

TextButton(
        child: Text("Time Pick"),
        onPressed: ()
        {
          FocusScope.of(context).unfocus();
          DatePicker.showTime12hPicker(
            context,
            showTitleActions: true,

            locale: LocaleType.en,
          );
        }
    )

output:

enter image description here

For both date and time use this package date_time_picker and initialize the date formatting

initializeDateFormatting('en');
TextButton(
          child: DateTimePicker(
            locale: Locale('en'),
            type: DateTimePickerType.dateTimeSeparate,
            dateMask: 'yyyy-MM-dd',
            initialValue: DateTime.now().toString(),
            firstDate: DateTime(2000),
            lastDate: DateTime.now(),
            icon: Icon(Icons.event),
            use24HourFormat: false,
            dateLabelText: 'Date',
            timeLabelText: "Hour",
            onChanged: (val) {
              print(val);

            },
          ),
      )

output: enter image description here

Upvotes: 2

HasanToufiqAhamed
HasanToufiqAhamed

Reputation: 971

                DatePicker.showTime12hPicker(
                  context,
                  showTitleActions: true,
                  locale: LocaleType.en,
                  currentTime: DateTime.now()
                );

Upvotes: 0

Taqi Raza Khan
Taqi Raza Khan

Reputation: 684

you may use

final format = DateFormat("HH:mm");

to sort out your issue..

Upvotes: 1

Related Questions