flutter - 我想拆分从 API 获得的数据并将其转换为日期和月份
问题描述
这是我从 API 调用数据的地方。
Center(
child: Container(
margin: EdgeInsets.symmetric(vertical: 1.5.h),
child: Column(
children: [
Text(
data[index].waktu, //this will show "2021/03/11" but all I want is only '03' and convert it to month
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white),
),
Padding(
padding:
EdgeInsets.only(top: 1.0.h),
child: Text(
data[index].waktu,//this will show "2021/03/11" but all I want is only '11'
style: TextStyle(
fontSize: 20.sp,
fontWeight: FontWeight.bold),
),
),
],
),
),
),
您能解释一下如何获取我想要的唯一数据并将其转换为月份名称吗?
解决方案
您需要使用DateFormat
from intl package 来解析您的格式,然后格式化为您需要的格式。
例如,对于您的第一个文本:替换
data[index].waktu,
和
DateFormat('MMMM').format(DateFormat("yyyy/MM/dd").parse(data[index].waktu)),
推荐阅读
- algorithm - 手动比较对象的有效方法?
- python - 关于生成特定长度数组的问题
- javascript - 在 vuejs 中使用条件内部过滤器()?
- html - 在按钮文本上方显示字体真棒图标作为链接
- java - 使用 Gradle 将环境变量添加到 Cucumber 任务
- python-3.x - Python - 有没有办法简化网页抓取代码?
- python - 如何从整数中取回数据。我的 model.predict() 不工作
- javascript - Google Maps API - 如何消除位置峰值
- angular - ag-Grid:获取鼠标所在行的索引
- javascript - 如何将数据从 laravel 控制器发送到 vuejs