0

这是我已经将其格式化为 [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),),

4

2 回答 2

0

您需要创建一个新的 DateFormat 对象。

final df = new DateFormat('yyyy-MM-dd');
Text(_selectedDate == null ? 'No Date Choosen!' : '${df.format(_selectedDate)}');
于 2020-07-08T11:14:00.647 回答
0

以下是如何格式化日期的示例:

  final DateTime now = DateTime.now();
  final DateFormat formatter = DateFormat('yyyy-MM-dd');
  final String formatted = formatter.format(now);
  print(formatted);
于 2020-07-08T11:15:17.913 回答