As you seen, i have a custom DatePicker widget and it takes the currentTime in DateTime type.
DatePickerWidget(
currentTime: DateTime.now(),
text: "$date1",
onChanged: (date) {
setState(() {
getProductDate(date.toString());
this.date1 = date.toString();
});
},
onConfirm: (date) {
setState(() {
getProductDate(date.toString());
this.date1 = date.toString();
});
},
),
but it's give me milliseconds too.
Result
YYYY-MM-JJ HH-MM:00.000
How can I remove the :00.000 part in DateTime type?
I just want to this format: 'yyyy-MM-dd'.
But currentTime is getting only DateTime type.
is there any idea?
my DatePickerWidget code:
class DatePickerWidget extends StatelessWidget {
final Function(DateTime data) onChanged;
final Function(DateTime data) onConfirm;
final String text;
final DateTime currentTime;
const DatePickerWidget(
{Key key, this.onChanged, this.onConfirm, this.text, this.currentTime})
: super(key: key);
@override
Widget build(BuildContext context) {
return ButtonWidget(
onPressed: () {
DatePicker.showDatePicker(context,
theme: DatePickerTheme(
containerHeight: context.dynamicHeight(0.3),
),
showTitleActions: true,
minTime: DateTime(2021, 1, 1),
maxTime: DateTime(2028, 12, 29),
onChanged: onChanged,
onConfirm: onConfirm,
currentTime: currentTime,
locale: LocaleType.tr);
},
text: text,
buttonColor: Colors.white,
borderColor: Colors.black,
textColor: Colors.black,
);
}
}