从格式如下的 API 调用中解析日期和时间时 2018 - 04 - 18T21:51:00
我得到并指出错误
我不明白我做错了什么。
/// I set in which format should my data be, and parse the data from the API call
Text('Date and Time:
${DateFormat("yyyy-MM-dd hh:mm:ss").format(DateTime.parse(apicall.timeanddate))}'),
之后,我将根据设备的区域设置语言首选项格式化日期和时间。
感谢任何帮助。
答案 0 :(得分:0)
您传递的格式无效,因此需要对其进行转换:
String getDateTime(String dateFromServer){
dateFromServer = dateFromServer.replaceAll(" ","");
dateFromServer = dateFromServer.replaceAll("T"," ");
return dateFromServer;
}
我替换了所有导致问题的空格和 T,您现在可以将其用于:
DateFormat("yyyy-MM-dd hh:mm:ss").format(getDateTime(apicall.timeanddate));
希望这能解决您的问题。