android - 如何在 Kotlin 中使用 "android.text.format.DateFormat"?

标签 android kotlin


    fun bind(crime: Crime){
            this.crime = crime
            titleTextView.text = this.crime.title
            val df : DateFormat = DateFormat.getInstance().format(DateFormat.LONG, DateFormat.MEDIUM)
            dateTextView.text = df.format(this.crime.date.toString())
            solvedImageView.visibility = if (crime.isSolved){
                View.VISIBLE
            }else{
                View.GONE
            }
        }
如何在 Kotlin 中使用日期格式库?
我想将此日期格式“Sun Jul 25 00:00:00 GMT+09:00 2021”更改为“Sun, Jul, 25, 2021”。

最佳答案

您可以简单地使用以下内容:

val formattedDate = SimpleDateFormat("EE, MMM, dd, yyyy", Locale.US)
val date = formattedDate .parse(this.crime.date.toString())

关于android - 如何在 Kotlin 中使用 "android.text.format.DateFormat"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68518225/

相关文章:

java - 如何在我的 Android 选项卡中创建 YouTube 应用程序?

Kotlin 默认构造函数

java - 如何使用 Kotlin 扩展 Java 类以像 static fun 一样使用?

java - 通过蓝牙将文件从PC发送到Android手机

Android MaterialButton 无法正确显示

android - 如何在 Android 设备中创建 Web 服务器(用于远程访问)

Android:显示表格数据的最佳方法

java - 使用 azure.keyvault.secret.property-sources 时 Spring Boot 应用程序启动失败并丢失日志

java - android的EditText的动态前导文本

android - 如何解决错误消息 : "Inheritance from an interface with ' @JvmDefault' members is only allowed with -Xjvm-default option"