gpt4 book ai didi

flutter - 如何将日期时间转换为字符串

转载 作者:行者123 更新时间:2023-12-03 04:00:44 34 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





How to format DateTime in Flutter

(15 个回答)


2年前关闭。




我正在尝试显示 DateTime作为 ListTile 中的文本.

我所做的事情给了我这样的信息:

The argument type 'String' can't be assigned to the parameter type 'DateTime'



代码:
_getDate() {
String formattedDate = DateFormat(yyyy-MM-dd).format(widget.exampleForDate.myDate);
return ListTile(
title: Text(formattedDate),
);
}

最佳答案

使用intl访问包DateFormat

DateTime dateTime = widget.exampleForDate.myDate; // your dateTime object
DateFormat dateFormat = DateFormat("yyyy-MM-dd"); // how you want it to be formatted
String string = dateFormat.format(dateTime); // format it

像这样使用它
ListTile(title: Text(string));

关于flutter - 如何将日期时间转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57106087/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com