我尝试在我的模型类中格式化时间。它需要第一行或发生错误。谁能帮忙?格式化时间需要API错误
@RequiresApi(api = Build.VERSION_CODES.N)
public String getFormattedTime() {
SimpleDateFormat formatter = new SimpleDateFormat("h a");
// Visit this link for demanded Date&Time formats
// https://developer.android.com/reference/java/text/SimpleDateFormat.html
formatter.setTimeZone(TimeZone.getTimeZone(getTimeZone()));
// Here requires a method to set the TimeZone in Main Activity (info gotten from online
// resources database)
Date dateTime = new Date(getTime() * 1000);
return formatter.format(dateTime);
}
你会得到什么错误? – SripadRaj
通话需要API等级24 – Rubit
奇怪的是,我在同一个项目中使用这个代码来处理其他模型类,并且完全没问题。 – Rubit