【发布时间】:2020-03-07 23:30:40
【问题描述】:
我想像 2019-07-08T10:37:28Z 这样格式化日期,但我不知道该怎么做,谁能帮我解决这个问题。
这是日期选择器的代码
final format = new DateFormat.yMMMEd('en-US');
return DateTimeField(
format: format,
autocorrect: true,
autovalidate: false,
controller: _bspLicenseExpiryDate,
readOnly: true,
validator: (date) => date == null ? 'Please enter valid date' : null,
decoration: InputDecoration(
labelText: "Expiry Date",
hintText: "Expiry Date",
prefixIcon: Icon(
FontAwesomeIcons.calendar,
size: 24,
)),
onShowPicker: (context, currentValue) {
return showDatePicker(
context: context,
firstDate: DateTime.now(),
initialDate: currentValue ?? DateTime.now(),
lastDate: DateTime(2100),
);
},
);
【问题讨论】:
-
DateTime有一个.toIso8601String()方法,但它会打印小数秒。试试print(DateTime.now().toUtc().toIso8601String());
标签: datetime flutter dart format flutter-layout