I wanted to categorised my photos by day, thus each photo is given a day timestamp (in UTC) they belong to based on their local date.
21 February 2019 at 18:18:13 UTC+8
->2019-02-21
7 April 2019 at 11:34:32 UTC+12
->2019-04-07
Save to Database
val date = ... // LocalDateTime// remove time from dateval dayDate = date.truncatedTo(ChronoUnit.DAYS)// convert to UTC Timestamp for storageval timestamp = dayDate.toTimestamp(ZoneOffset.UTC)
NOTE: Refer to Covert LocalDateTime (java.time) to Firestore Timestamp
Read from Database
val timestamp = ...val dayDate = timestamp.toLocalDateTime(ZoneOffset.UTC)