Created
October 22, 2018 13:47
-
-
Save ahndwon/b01a1805e2afaeb4f6445d328e45bb21 to your computer and use it in GitHub Desktop.
get elapsed time(sec, min, hours, days, month) from java date in Korean
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun Date.getPassedTime(): String { | |
val millis = Date().time - this.time | |
val sec = millis / 1000 | |
val min = millis / (60 * 1000) | |
val hour = millis / (60 * 60 * 1000) | |
val day = millis / (24 * 60 * 60 * 1000) | |
val week = millis / (7 * 24 * 60 * 60 * 1000) | |
val month = (millis / (30.5 * 24 * 60 * 60 * 1000)).toInt() | |
//val year = day / 365 | |
return when { | |
day >= 365 -> "${(day / 365)}년 전" | |
month > 0 -> "${month}달 전" | |
week > 0 -> "${week}주 전" | |
day > 0 -> "${day}일 전" | |
hour > 0 -> "${hour}시간 전" | |
min > 0 -> "${min}분 전" | |
else -> "${sec}초 전" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment