【发布时间】:2021-05-26 16:38:18
【问题描述】:
如您所见,我有一个自定义 DatePicker 小部件,它采用 DateTime 类型的 currentTime。
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();
});
},
),
但它也给了我几毫秒。
结果
YYYY-MM-JJ HH-MM:00.000
如何删除 DateTime 类型中的 :00.000 部分?
我只想要这种格式:'yyyy-MM-dd'。
但 currentTime 只获得 DateTime 类型。
有什么想法吗?
我的 DatePickerWidget 代码:
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,
);
}
}
【问题讨论】:
-
不,我也已经检查过了。我的问题不同:/
-
不同如何?这是一个精确的副本。为什么你的问题不一样?
-
先生,我的当前时间只有“日期时间”类型。我检查了您问题中的所有解决方案,但对我不起作用:(
-
哪个代码显示日期?我的意思是从你的图像。