这是我已经将其格式化为 [yyyy-MM-dd] 但它还包含 00:00:00 的代码:
child: Text(
_selectedDate == null
? 'No Date Choosen!'
: '${DateFormat('yyyy-MM-dd').format(_selectedDate)}',
style: TextStyle(
color: Colors.white, fontSize: 16),),
您需要创建一个新的 DateFormat 对象。
final df = new DateFormat('yyyy-MM-dd');
Text(_selectedDate == null ? 'No Date Choosen!' : '${df.format(_selectedDate)}');
以下是如何格式化日期的示例:
final DateTime now = DateTime.now();
final DateFormat formatter = DateFormat('yyyy-MM-dd');
final String formatted = formatter.format(now);
print(formatted);