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