Kotlin
@Choltski समाधान लेकिन सेकंड के साथ और कोटलिन में
fun getMyPrettyDate(neededTimeMilis: Long): String? {
val nowTime = Calendar.getInstance()
val neededTime = Calendar.getInstance()
neededTime.timeInMillis = neededTimeMilis
return if (neededTime[Calendar.YEAR] == nowTime[Calendar.YEAR]) {
if (neededTime[Calendar.MONTH] == nowTime[Calendar.MONTH]) {
if (neededTime[Calendar.DATE] - nowTime[Calendar.DATE] == 1) {
"Tomorrow at " + DateFormat.format("HH:mm:ss", neededTime)
} else if (nowTime[Calendar.DATE] == neededTime[Calendar.DATE]) {
"Today at " + DateFormat.format("HH:mm:ss", neededTime)
} else if (nowTime[Calendar.DATE] - neededTime[Calendar.DATE] == 1) {
"Yesterday at " + DateFormat.format("HH:mm:ss", neededTime)
} else {
DateFormat.format("MMMM d, HH:mm:ss", neededTime).toString()
}
} else {
DateFormat.format("MMMM d, HH:mm:ss", neededTime).toString()
}
} else {
DateFormat.format("MMMM dd yyyy, HH:mm:ss", neededTime).toString()
}
}
date.getTime()
जैसे आउटपुट पाने के लिए आप यहां से गुजर सकते हैं
Today at 18:34:45
Yesterday at 12:30:00
Tomorrow at 09:04:05