我正在firestore工作,但时间戳出现了一些问题。我想使用android studio中的datepicker根据日期进行过滤。我只想比较月份和月份的日期。我认为会很好,但是时间问题了,
示例:
firestore:Sat May 18 23:21:20 GMT+07:00 2019
datepicker:Sat May 18 05:46:27 GMT+07:00 2019
下面是一些用于选择时间戳记的代码:
fun initClasses(date: Date, onComplete: () -> Unit){
currentUserDocRef.get()
.addOnSuccessListener {
currentUserDocRefAddClasses.get().addOnSuccessListener { documentSnapshot ->
// Log.d("test", "name: " + it.get("name") + " id: " + it.id)
val newClasses = Classes(it.id,"",it.get("name").toString(),"", date)
currentUserDocRefAddClasses.document().set(newClasses).addOnSuccessListener {
onComplete()
Log.d("success1","success")
}
}
}
}
日期选择器的代码:
floatingActionButtonClass.setOnClickListener {
var date = DatePickerDialog
.OnDateSetListener { view, year, month, dayOfMonth ->
calendar.set(Calendar.YEAR, year)
calendar.set(Calendar.MONTH, month)
calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth)
Log.d("tag261", calendar.time.toString())
FirestoreUtil.initClasses(calendar.time as Date){
toast("berhasil input")
}
}
DatePickerDialog(
this, date,
calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH)
).show()
}
谢谢