forked from penguin86/luna-tracker
Compare commits
3 Commits
50baa76d35
...
f3fb584ec2
| Author | SHA1 | Date | |
|---|---|---|---|
| f3fb584ec2 | |||
| f38b889248 | |||
| 301e8d0476 |
@@ -1,7 +1,6 @@
|
||||
package utils
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.text.format.DateFormat
|
||||
import it.danieleverducci.lunatracker.R
|
||||
import java.util.Date
|
||||
@@ -108,19 +107,15 @@ class DateUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Format time as localized string without seconds. E.g. "Sept 18, 2025, 03:36 PM".
|
||||
* Format time as localized string. E.g. "28 Sept 03:36:00".
|
||||
* The seconds are set to 0 since they are distracting and not relevant.
|
||||
* Used in the event detail dialog.
|
||||
*/
|
||||
fun formatDateTime(unixTime: Long): String {
|
||||
val date = Date(unixTime * 1000)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
val dateFormat = android.icu.text.DateFormat.getDateTimeInstance(android.icu.text.DateFormat.RELATIVE_SHORT, android.icu.text.DateFormat.SHORT)
|
||||
return dateFormat.format(date)
|
||||
} else {
|
||||
// fallback
|
||||
val roundedUnixTime = unixTime - (unixTime % 60)
|
||||
val date = Date(roundedUnixTime * 1000)
|
||||
val dateFormat = java.text.DateFormat.getDateTimeInstance()
|
||||
return dateFormat.format(date)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user