如何在Flutter中更改日期和时间格式? [英] How to change date and time format in flutter?
本文介绍了如何在Flutter中更改日期和时间格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好吗?
我的后端只接受这种格式的日期和时间2019-03-24 11:00:00
my backend just accept date and time in this format 2019-03-24 11:00:00
并且我在我的应用程序日历小部件中使用以获取日期,并以这种格式打印日期2019-04-24 12:00:00.000Z,我使用此代码获取时间
and i use in my app calendar widget to get the date and it print the date in this format 2019-04-24 12:00:00.000Z and i use this code to get the time
TimeOfDay _time = new TimeOfDay.now();
Future<Null> _selecTime(BuildContext context) async {
final TimeOfDay picked = await showTimePicker(
context: context,
initialTime: _time,
);
if (picked != null && picked != _time) {
print('${_time.toString()}');
setState(() {
_time = picked;
});
}
}
,我得到这个TimeOfDay(07:37)
and i get this TimeOfDay(07:37)
所以我如何获取日期为2019-04-24的格式和时间为11:00:00的格式,我将处理
so how can i get format for date like this 2019-04-24 and for time like this 11:00:00 and i will deal with it
谢谢
推荐答案
您可以使用 intl软件包
这里是一个示例:
import 'package:intl/intl.dart';
main() {
var now = new DateTime.now();
var dateFormat = new DateFormat('yyyy-MM-dd HH:mm:ss');
String formattedDate = dateFormat.format(now);
print(formattedDate); // 2019-04-28 09:02:29
}
这篇关于如何在Flutter中更改日期和时间格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文