Open srseibs opened 3 weeks ago
@RequiresApi(Build.VERSION_CODES.O) fun convertMillisToLocalDate(millis: Long): ZonedDateTime { // Interpret the milliseconds as the start of the day in UTC, then convert to localdate val utcDateAtStartOfDay = Instant .ofEpochMilli(millis) .atZone(ZoneOffset.UTC) .toLocalDate() println("UTC Date at Start of Day: $utcDateAtStartOfDay") // Debugging UTC date // Convert to the same instant in Local time zone val localDate = utcDateAtStartOfDay.atStartOfDay(ZoneId.systemDefault()) println("Local Date: $localDate") // Debugging local date return localDate } 1 . I am converting the Instant to ZonedDateTime at UTC time zone and then getting only the date portion by converting it to local date.
That seems to work! Thanks.
I think there is an error related to time zones. I am located in California and it is presently 5:46 PM Pacific Daylight Time (GMT - 7). The date picker calendar shows I selected Sep 03, but the TextView shows the value to be Sep 02.
I had a similar problem with my own app, saw your Medium article with a sample, and was hoping it would work better than mine.