在flutter中更改日期时间格式,使其仅保留日期 [英] change the datetime format in flutter, to leave it only with the date

查看:81
本文介绍了在flutter中更改日期时间格式,使其仅保留日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在flutter中更改日期时间格式,使其仅保留日期.我还想知道是否还有另一个仅包含日期的小部件.

I would like to know how I can change the datetime format in flutter, to leave it only with the date. I also want to know if there is another widget that only contains the date.

谢谢

推荐答案

您可以从intl包中使用DateFormat.有了它,您可以自定义为所需的任何格式.

You can use DateFormat from intl package. With it you can custom to any format that you need.

添加到pubspec.yaml

Add to pubspec.yaml

dependencies:
  intl: ^0.15.7

在Dart代码上:

import 'package:intl/intl.dart';

final dateFormatter = DateFormat('yyyy-MM-dd');
final dateString = dateFormatter.format(DateTime.now());

然后,您可以将字符串放入任何窗口小部件中.示例:

Then you can put the string into any widget. Example:

Text(dateString)

关于日期格式: https://www.cl.cam.ac.uk/~mgk25/iso-time.html

这篇关于在flutter中更改日期时间格式,使其仅保留日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆