更新UI
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.aiosman.riderpro.exp
|
||||
|
||||
import android.icu.text.SimpleDateFormat
|
||||
import android.icu.util.Calendar
|
||||
import com.aiosman.riderpro.data.api.ApiClient
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
@@ -22,4 +23,18 @@ fun Date.timeAgo(): String {
|
||||
days < 365 -> "$days days ago"
|
||||
else -> "$years years ago"
|
||||
}
|
||||
}
|
||||
|
||||
fun Date.formatPostTime(): String {
|
||||
val now = Calendar.getInstance()
|
||||
val calendar = Calendar.getInstance()
|
||||
calendar.time = this
|
||||
val year = calendar.get(Calendar.YEAR)
|
||||
var nowYear = now.get(Calendar.YEAR)
|
||||
val dateFormat = if (year == nowYear) {
|
||||
SimpleDateFormat("MM-dd", Locale.getDefault())
|
||||
} else {
|
||||
SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
|
||||
}
|
||||
return dateFormat.format(this)
|
||||
}
|
||||
Reference in New Issue
Block a user