我嘗試在我的模型類中格式化時間。它需要第一行或發生錯誤。誰能幫忙?格式化時間需要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