How to set value of DateTimeType in document

I would like to add an IFieldInstance to a document which is in the model described as DateTimeType but I get an Error.

The relevent part of the model:

{
  "type": "Field",
  "id": "field_d8d6b",
  "name": "timestamp_last_edit",
  "Field": {
    "fieldType": {
      "type": "DateTimeType",
      "DateTimeType": {
        "format": "yyyy-MM-dd'T'HH:mm:ss"
      }
    },
    "label": [
      {
        "locale": "en",
        "text": "Last edit"
      }
    ]
  }
}

How the date-time is added:

IFieldInstance fieldInstance = documentFactory.createFieldInstance(fieldToPath(field), repitition);
document.removeEntityInstance(fieldInstance);
fieldInstance.setValue("2023-02-01T11:28:40");
document.addEntityInstance(fieldInstance);

The error:

Caused by: java.lang.IllegalArgumentException: The given value is syntactically wrong and that's why it cannot be converted to the corresponding approximated date-object.
	at com.mgmtp.a12.kernel.core.rt._27_3_0.internal.util.TeilbekanntesDatumUtil.parseApproximatedDate(TeilbekanntesDatumUtil.java:248)
	at com.mgmtp.a12.kernel.md.facade.a12internal.KernelUtils.getApproximatedDate(KernelUtils.java:61)
	at com.mgmtp.a12.dataservices.model.internal.TimeFormatUtils.handlePartiallyKnownDates(TimeFormatUtils.java:92)
	at com.mgmtp.a12.dataservices.search.internal.AbstractIndexDocument.lambda$addDateField$10(AbstractIndexDocument.java:97)

It seems like A12 is using the parseApproximatedDate() function which only uses “yyyy-MM-dd” and therefore the format does not match.
Why is it using approximateDate?

How to set the date time correctly on the fieldInstance?

Hi @sebastian-modular-forge, even this way (using the string as value) should work, you can set the corresponding object value instead. For that, you can use the method IDocumentService#convertToJavaType(IFieldInstance, String, Consumer).
When is the error thrown?

The error was thrown when trying to save the workflow-document with the new FieldInstance after listening on DocumentAfterCreateEvent/DocumentAfterUpdateEvent.
In the meantime I got it working with your proposed convertToJavaType() and it also worked by setting the corresponding Java type directly instead of using a formatted string.