Reputation: 513
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.
Upvotes: 1
Views: 5238
Reputation: 41
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;
});
Upvotes: -1
Reputation: 132
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
Upvotes: 2
Reputation: 240
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;
});
Upvotes: 0