【发布时间】:2021-12-21 05:30:12
【问题描述】:
我想列出最新的订单直到最旧的订单。我已经在用户付款之前设置了日期格式。
// Get current date & time
val currentDateTime = LocalDateTime.now()
// Format date time style
currentDateTime.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM))
// Finalize convert format
val date = DateTimeFormatter.ofPattern("dd MMM yyyy, HH:mm").format(currentDateTime)
用户付款后,它会添加到我的 Firestore。当我检索数据时,它只是按月的日期递减。
fun getOrderList(activity: Fragment, recyclerView: RecyclerView) {
mFirestore.collection(Constants.ORDERS)
.orderBy("date", Query.Direction.DESCENDING)
.get()
.addOnSuccessListener { result ->
val orderItem = result.toObjects(UserOrderList::class.java)
recyclerView.adapter = OrderListItemAdapter(activity, activity.requireContext(), orderItem)
}
}
我的日期输出像 2021 年 6 月 6 日 10:50 -> 2021 年 11 月 5 日 14:22 -> 2021 年 5 月 3 日 10:58 -> 2021 年 4 月 3 日 09:13
如何将日期从最新到最旧排序并将其列出到我的 RecyclerView 中?
【问题讨论】:
-
请编辑您的问题并将您的数据库结构添加为屏幕截图。
-
@AlexMamo 我已经上传了我的数据库结构。我应该如何编辑我的问题?
标签: android firebase kotlin google-cloud-platform google-cloud-firestore