【发布时间】:2020-09-11 06:16:07
【问题描述】:
我正在使用Github Library 以TextView 的格式显示时间,就像刚才、昨天、很久以前......等等。它显示了我想要的时间。但问题是时间并没有改变,因为它是 刚刚 在 post-it 的那一刻永远保持不变。
postAdapter的模型类
class Post {
private var date: String = ""
constructor(date: Long) {
fun getDate(): String
{
return date
}
//Initialization according to the library
val timeInMillis = System.currentTimeMillis()
val timeAgo = TimeAgo.using(timeInMillis)
//saving the data to firestore
val fStore: FirebaseFirestore = FirebaseFirestore.getInstance()
val post = Post(title, description, date = timeAgo)
fStore.collection("Posts").document()
.set(post)
.addOnSuccessListener{...}
从Firestore检索数据
private fun postInfo(title: TextView, description: TextView, date: TextView) {
val postRef = FirebaseFirestore.getInstance().collection("Posts").document()
postRef.get()
.addOnSuccessListener { documentSnapshot ->
if (documentSnapshot != null && documentSnapshot.exists()) {
val post = documentSnapshot.toObject(Post::class.java)
date.text = post?.getDate()
title.text = post?.getTitle()
description.text = post?.getDescription()
}
}
}
【问题讨论】:
-
显示屏幕截图以查看日期在 Firestore 中的存储方式。
-
请更新问题检查。
-
post?.getDate()返回什么,作为字符串的长值,对吧? -
是的@AlexMamo :(
-
您似乎仍在接收 long 值。您是否尝试过可以进一步将“timeAgo”与“.ToString()”进行转换?除此之外,此日期值是否对应于 Firestore 时间戳?您是否尝试过使用任何其他库而不是这个特定的 TimeAgo?
标签: android kotlin google-cloud-firestore android-dateutils