【发布时间】:2021-12-21 12:18:27
【问题描述】:
在我从 Firestore 的时间戳中检索数据字段的日期之后。我想在我的回收站视图中将时间戳日期格式化为“dd MMM yyyy, HH:mm”。我尝试使用 DateTimeFormatter 但它不起作用。
override fun onBindViewHolder(holder: OrderListViewHolder, position: Int) {
val item = orderList[position]
orderViewModel.setOrderProduct(item.foodItem)
orderViewModel.setStatus(item.status)
val foodItem = item.foodItem?.map { it.itemName }
val date = Date(item.date!!.toDate().time)
val newDate = date.toString().substring(0, 16) + date.toString().substring(29, 34)
val formatter = DateTimeFormatter.ofPattern("dd MMM yyyy, HH:mm")
val formattedDate = newDate.format(formatter)
Log.d("dates", "${formattedDate}")
holder.orderDate.text = formattedDate
holder.foodName.text = foodItem.toString().removeSurrounding("[", "]")
holder.status.text = orderViewModel.status.value.toString()
}
目前,我只知道如何使用子字符串来设计我的日期格式。但这不是我的预期。 如何设置时间戳格式?
【问题讨论】:
-
“它不起作用” 为什么不呢?你希望这段代码做什么?而它的作用是什么?
-
@FrankvanPuffelen 我只想格式化我的日期
标签: android firebase kotlin google-cloud-firestore