How do I convert a mongo date to a string

I’m trying to use realm from an android app. I’m working my way through the tutorial. I’ve setup a simple watch. It appears that I need to convert a mongo date to a string , but the question is how do I do this ?

This is the field in the mongo doc

  "dateTime": {
    "$date": {
      "$numberLong": "1644483300000"

This is part of the RealmObject layout for this (java)

public class RealmLogEntry extends RealmObject {
//public class RealmLogEntry implements RealmModel {

    private String _id;

    String userId;

    String dateTime;

I have setup a watch on the collection, but when I change the collection (via postman) , I get this error when running the android app using Java in android studio. I understand the error, I’m trying to figure out how to move past it. i.e. convert the dateTime on the mongoDB doc to a string, I’ve tried changing from a String to a Date type in the Realm Object layout but I can’t get that to work either.

org.bson.codecs.configuration.CodecConfigurationException: An exception occurred when decoding using the AutomaticPojoCodec.
    Decoding into a 'RealmLogEntry' failed with the following exception:
    Failed to decode 'RealmLogEntry'. Decoding 'dateTime' errored with: readString can only be called when CurrentBSONType is STRING, not when CurrentBSONType is DATE_TIME.

I’m sorry I can’t help you. I did not progress with this field , I commented it out. I am using mongoDB as a beginner, to evaluate for further use.

Good luck.

If your dates are stored using the date data type you should manipulate them as data object in your code.

If your dates are not stored using the date data type you should migrate your data to store the date as date data type rather than string.

You then format the date, using the user’s LOCALE, only when you present it to the user.