我想格式化日期像这样的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),
);
},
);发布于 2019-11-12 19:05:30
您可以使用以下命令:
var now = new DateTime.now();
var dateFormatted = DateFormat("yyyy-MM-ddTHH:mm:ss").format(now);您必须在字符串的末尾添加"Z“,因为它是用于格式化TimeZone的字符。
您可以在-> https://pub.dev/documentation/intl/latest/intl/DateFormat-class.html上查看
https://stackoverflow.com/questions/58815575
复制相似问题