Created
October 21, 2020 09:40
-
-
Save nadar71/314637c1d35c7eafbbadc89db9ec7a6b to your computer and use it in GitHub Desktop.
Returns the number of milliseconds (UTC time) for today's date at midnight in the local time zone
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
// Returns the number of milliseconds (UTC time) for today's date at midnight in the local time zone | |
val normalizedUtcMsForToday: Long | |
get() { | |
val utcNowMillis = System.currentTimeMillis() | |
val currentTimeZone = TimeZone.getDefault() | |
val gmtOffsetMillis = currentTimeZone.getOffset(utcNowMillis).toLong() | |
val timeSinceEpochLocalTimeMillis = utcNowMillis + gmtOffsetMillis | |
val daysSinceEpochLocal = | |
TimeUnit.MILLISECONDS.toDays(timeSinceEpochLocalTimeMillis) | |
return TimeUnit.DAYS.toMillis(daysSinceEpochLocal) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment