无法在textView中显示获取的unix时间

Arn*_*hra 2 android android-layout firebase firebase-realtime-database

我正在使用firebase构建一个应用程序作为我的后端.

我使用了ServerValue.TIMESTAMP并将一个写操作的unix时间存储在一个名为的变量中timeStamp.

我所执行的下面线及有下方的红线new SimpleDateFormat("H:mm",Locale.US);format.

hovertext读取:

"Call requires API level 24 (current min is 15) android.icu.text.SimpleDateFormat#SimpleDateFormat     
Run Code Online (Sandbox Code Playgroud)

这是我在RecyclerView.ViewHolder类中的代码:

SimpleDateFormat simpleDateFormat=new SimpleDateFormat("H:mm");
simpleDateFormat.format(timeStamp));
noticeTimeStampTextView.setText(simpleDateFormat);
Run Code Online (Sandbox Code Playgroud)

在按下运行按钮后,我得到了这个:

Error:(32, 32) error: no suitable method found for setText(SimpleDateFormat)
method TextView.setText(CharSequence) is not applicable
(argument mismatch; SimpleDateFormat cannot be converted to CharSequence)
method TextView.setText(int) is not applicable
(argument mismatch; SimpleDateFormat cannot be converted to int)
Run Code Online (Sandbox Code Playgroud)

我该怎么解决这个问题?

Ben*_*Ben 8

您需要使用java.text.SimpleDateFormat而不是Android.这将适用于您所针对的api级别.这与将一个字符串传递给另一个答案中提到的setText一起.