android - 如何在 Kotlin 中使用“android.text.format.DateFormat”?
问题描述
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())
推荐阅读
- php - 在 HTML 中使用 PHP 文件变量加载 WAV 音频文件
- reactjs - React Router - 嵌套路由,在子应用程序中隐藏父组件
- reactjs - 无法安装反应应用程序“UnhandledPromiseRejectionWarning:错误:EBUSY:资源繁忙或锁定”
- javascript - 多个下拉框?
- java - 在 Linux 系统上使用 Java Printable 保存 PDF 文件
- jquery - 格式转换数字的问题
- scala - 从条件中删除“return”关键字时的无用表达式
- python - 在没有确切单词、数字等的情况下对字典中的字典进行排序 - Python
- gltf - 一个网格对象具有不同颜色的多个图元 (glTF 2)
- sharepoint - 当用户共享文档时,是否可以在页面或弹出窗口上显示警报消息