Home > Enterprise >  Flutter DatePicker change format to MM-DD-YYYY
Flutter DatePicker change format to MM-DD-YYYY

Time:09-15

                      DatePicker.showDatePicker(
                        context,
                        showTitleActions: true,
                        minTime: DateTime(1964, 1, 1),
                        maxTime: DateTime(2030, 12, 31),
                        onChanged: (newDateTime) {
                          setState(() {
                            selectedDate = Jiffy(DateTime(
                              newDateTime.month,
                              newDateTime.day,
                              newDateTime.year,
                              newDateTime.hour,
                              newDateTime.minute,
                              newDateTime.second,
                            )).format('MMM dd, yyy, hh:mm:ss');
                            dateTimeSelected = newDateTime;
                          });

So I'm in my Dart file of my client's app they want me to take a look at, and I found the Flutter package call for the DatePicker, but have no idea how to change it to MM-DD-YYYY. This is my code that I tried modifying, but I think its just how it feeds the string format, not the actual user display. I can't seem to google the right combo to find a concrete answer either. I saw 1 dead thread that had a similair question, and another person asked, but I guess they gave up and used an Android package? The main issue is this is designed as an Android and IOS app, and Flutter allows that level of platform flexibility I need. I'm new to the world of mobile app development, but I have been reading the documentation on this DatePicker package with little luck. I'm hoping the community could help.

CodePudding user response:

DatePicker.showDatePicker(
                        context,
                        showTitleActions: true,
                        minTime: DateTime(1964, 1, 1),
                        maxTime: DateTime(2030, 12, 31),
                        onChanged: (newDateTime) {
                          setState(() {
                            selectedDate = Jiffy(DateTime(
                              newDateTime.month,
                              newDateTime.day,
                              newDateTime.year,
                              newDateTime.hour,
                              newDateTime.minute,
                              newDateTime.second,
                            )).format('MM-dd-yyyy');
                            dateTimeSelected = newDateTime;
                          });

CodePudding user response:

DatePicker is only themed for android theme only, if you want to use ios theme on ios platform then try to using a case so it gonna show the cupertino datepicker when you click it. If you meant to change the datepicker format on user display i suggest you to try and look this page DatePicker flutter change display date format

CodePudding user response:

You can check the date format

https://api.flutter.dev/flutter/intl/DateFormat-class.html

source from

How to change Date Picker default date format in Flutter

  • Related