SimpleDateFormat提供API错误 [英] SimpleDateFormat gives API Error
问题描述
每当我在android中使用我的 SimpleDateFormat
时,它一直给我错误调用需要API级别24.这是没有意义的,因为我引用this 这是几年前的教程。
Whenever I use my SimpleDateFormat
in android it keep giving me the error call requires API level 24. Which doesn't make sense since I refer to this tutorial which was a couple of years old.
这是发出错误的代码
SimpleDateFormat formatter = new SimpleDateFormat(EEE,dd MMM,yyyy HH:mm:ss);
我甚至尝试但它仍然无法正常工作
I even try but it's still not working
SimpleDateFormat formatter = new SimpleDateFormat(EEE,dd MMM,yyyy HH:mm:ss,Locale.US) ;
这是我的方法,我遇到问题
Here is my method where I'm having problem with
public static long getDateInMillis(String srcDate) {
SimpleDateFormat formatter = new SimpleDateFormat("EEE,dd MMM yyyy HH:mm:ss");
long dateInMillis = 0;
try {
Date date = formatter.parse(srcDate);
dateInMillis = date.getTime();
return dateInMillis;
}
catch (java.text.ParseException e) {
e.printStackTrace();
}
return 0;
}
推荐答案
这是因为你导入了 android.icu.text.SimpleDateFormat 而不是java.text.SimpleDateFormat 。
It's because you imported android.icu.text.SimpleDateFormat instead of java.text.SimpleDateFormat.
这篇关于SimpleDateFormat提供API错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!