Based on your output, it seems the conversion functions are working as intended. The timestamp 1728597600000 corresponds to October 10th, 2024, in UTC. When converted to the Europe/Berlin time zone, it correctly becomes October 11th, 2024, due to the time difference.
You can check below mentioned point :
Daylight Saving Time:
Ensure that your logic accounts for daylight saving time, which seems correct given your output. Berlin is UTC+2 during daylight saving time.
DatePicker Initialization:
Verify that the DatePicker correctly interprets the initial timestamp. The timestamp should correspond to the local start of the day (midnight) on October 11th.
Conversion and Display:
Ensure that the conversion from timestamp to LocalDate and back to timestamp doesn’t introduce any off-by-one errors. Your current functions appear correct, but double-check that DatePicker uses the correct initialSelectedDateMillis.
Check DatePicker Logic:
Review the CustomDatePickerDialog implementation to ensure it initializes and updates correctly. Make sure it correctly interprets the timestamp in the local time zone.
println("Initial LocalDate: ${selectedDate.value}") // Should print 2024-10-11 println("Initial Timestamp: ${initialTimestamp}") // Should be 1728597600000 println("Selected Timestamp: ${datePickerState.selectedDateMillis}") // Check this value println("Converted LocalDate: ${convertTimestampToLocalDate(datePickerState.selectedDateMillis!!)}") // Should print 2024-10-11
Also ensure that selectedDateMillis is not null before using it in convertTimestampToLocalDate.