如何在 Flutter 中格式化日期时间 [英] How to format DateTime in Flutter
本文介绍了如何在 Flutter 中格式化日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在点击按钮后在 Text
小部件中显示当前的 DateTime
.以下有效,但我想更改格式.
I am trying to display the current DateTime
in a Text
widget after tapping on a button. The following works, but I'd like to change the format.
目前的方法
DateTime now = DateTime.now();
currentTime = new DateTime(now.year, now.month, now.day, now.hour, now.minute);
Text('$currentTime'),
结果
YYYY-MM-JJ HH-MM:00.000
问题
如何删除 :00.000
部分?
推荐答案
您可以使用来自 DateFormat="noreferrer">intl 包.
You can use DateFormat
from intl package.
import 'package:intl/intl.dart';
DateTime now = DateTime.now();
String formattedDate = DateFormat('yyyy-MM-dd – kk:mm').format(now);
这篇关于如何在 Flutter 中格式化日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文