flutter - how to get only day number from date in flutter
问题描述
I am trying to get day from date, and date comes from the api response, api response look like this
"data": [
{
_id: 6116c2e12760f71630342604,
username: 'abc',
Date: '2021-08-13',
},
{
_id: 6119ba9162069c32ccdf11c3,
username: 'acv',
Date: '2021-08-15',
}
]
i am trying to do it like this
date=Response.data['data']['Date']); //if i get date here 2021-08-15
day=date.split('-') //then will split it [2021,08,05]
day=date[2] //and then will get the day 05
but it is not working, it sends this error
type 'String' is not a subtype of type 'int' of 'index'
when i print this line day=Response.data['data']['Date']);
it send same error, it is not getting date, but when i print onResponse.data
it prints the api response.
please help how to do this
解决方案
Let's try or you will use day[2]
day=Response.data['data']['Date']); //if i get date here 2021-08-15
day=date?.split('-').last; //then will split [05]
print(day) //and then will get the day 05
推荐阅读
- python - 如何在 Python 3 中一致地切片字符串的第一个和最后一个字符
- python-3.x - Pandas groupby 每组并将每一行除以其总和
- kubernetes - Kubernetes 内存限制:同一个 pod 上有和没有内存限制的容器
- r - R中多个数据集的T.test
- linux - 内核糟糕转储:为什么堆栈数据丢失?
- javascript - 根据日期显示某些图标的替代方法使用 IF 语句
- lisp - 这可能是我在其他包中的词法绑定特殊 var 吗?
- c++ - 有没有办法告诉你在 Mac 上的 Visual Studio 上运行的 C++ 版本是什么?
- python - 如何在 python 中从 xml 中提取元素、子元素和完整路径?
- python - 如何在python中使用数据框检查后附加列名