0
                      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.

EDIT: This is for anyone passing through with a similar question. It seems like finding where it sets the DateFormat and changing it to DateFormat.yMMMMd('en_US') will set it to the US standard of MM-DD-YYYY.

EDIT 2: I can't even set the DateFormat, or have no idea where to set it, due to the stupid use of Jiffy in our project. Investigating further, because this question sadly isn't solved yet.

Powermaster Prime
  • 402
  • 1
  • 2
  • 16
  • String convertDate= DateFormat("MM-dd-yyyy").format(DateTime.now()); You can add whatever you want instead of the current date and convert it. even if you go inside the DateFormat class, it gives you a clearer idea about the package, including how you want to write it there. – hasan karaman Sep 15 '22 at 04:57

3 Answers3

2

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

Saleem Yasin
  • 120
  • 5
  • Saleem, thank you for linking that exact page, because it helped me find exactly what I needed! I'm at work now, but as soon as I'm home to test this, I will update my question. It seems like `DateFormat.yMMMMd('en_US') -> July 10, 1996` will get me what I need, and I know exactly where in my code I saw that. This community has been extremely helpful with this project, and I can't thank everyone enough – Powermaster Prime Sep 15 '22 at 12:49
1
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;
                          });
0
 late DateTime selectedDate;

     DatePicker.showDatePicker(
                            context,
                            showTitleActions: true,
                            minTime: DateTime(1964, 1, 1),
                            maxTime: DateTime(2030, 12, 31),
                            onChanged: (newDateTime) {
                          setState(() {
                      selectedDate = newDateTime;});

                  var date = DateTime.parse(selectedDate.toString());    
                                         
         var formattedDate = "${date.month}-${date.day}-${date.year}";                                                          
                     dateTimeSelected = formattedDate;
                              });
naveen_kc
  • 43
  • 4