Okay so in my application from a Date/Time picker I’m allowing a user to make a choice. That choice is later represented as a LocalDateTime type. Now I want to upload that LocalDateTime to Mongo DB Atlas/Realm. However the type that I’ve defined in the schema is a date (RealmInstant).
So my question is, how can I convert a “LocalDateTime” into a “RealmInstant” format?
Then in the database I get a different date format:
A regular RealmInstant date format: +054860-03-23T17:21:49.000+00:00
Date format when I convert LocalDateTime into RealmInstant: 2022-11-21T19:12:42.000+00:00
As you can see those two do not have the same formatted string in the database.
And when I parse the second example in my app, instead of the correct date, I’m getting a year 1970:
This works for me, both localDP & date return the same value, didn’t check on Atlas.
val localDP = LocalDateTime.parse("2022-11-21T19:12:42")
val realmDP = RealmInstant.from(localDP.toEpochSecond(ZoneOffset.UTC), localDP.nano)
val date = LocalDateTime.ofEpochSecond(realmDP.epochSeconds, realmDP.nanosecondsOfSecond, ZoneOffset.UTC)
Log.e("Container", "Container: $realmDP -- $date.")