API ignores 'Z' char - UTC indicator, or explicit zone. If posted as local (without zone info) it is parsed as UTC ... ?!?
I am unable to create a list item with DateTime field. Since documentation neither API did not comment it, I presume that dateTime format should be the same as is returned from server (full iso, e.g.: "Modified": "2021-06-22T02:35:15Z").
Unfortunatelly, the only way how to post a value is strip zone completelly )-:
The problem is in: HTTP API (REST) and java API.
Sample request:
POST https://graph.microsoft.com/v1.0/sites/siteId/lists/listId/items
Content-Type: application/json
Authorization: Bearer token
{
"fields": {
"Title": "any title",
"timestamp": "2021-06-22T12:00:00"
}
}
Sample code:
Instant now = Instant
.now()
.truncatedTo(ChronoUnit.SECONDS)
;
String timestampString = DateTimeFormatter.ISO_INSTANT.format(now);
System.out.println("timestampString=" + timestampString);
FieldValueSet fieldValueSet = new FieldValueSet();
fieldValueSet.additionalDataManager().put("timestamp", new JsonPrimitive(timestampString));
listItem.fields = fieldValueSet;
ListItem li = graphClient
.sites(siteId)
.lists(listId)
.items()
.buildRequest()
.post(listItem);
System.out.println("createdDateTime=" +li.createdDateTime);
}
RESULT LOG:
timestampString=2021-06-22T08:58:02Z
createDateTime= 2021-06-22T01:58:02Z
HTTP requests examples:
Request: "begin": "2000-01-01T00:00:00Z"
Response: "begin": "1999-12-31T16:00:00Z"
-8h
Request: "begin": "2021-06-22T12:00:00+02:00"
Response: "begin": "2021-06-22T03:00:00Z"
-?h
Request: "begin": "2021-06-22T12:00:00Z"
Response: "begin": "2021-06-22T05:00:00Z"
-7h
Request: "begin": "2021-06-22T12:00:00"
Response: "begin": "2021-06-22T12:00:00Z"
Ignores UTC - Z char ...
See also:
https://stackoverflow.com/questions/66283825/microsoft-graph-api-insert-new-listitem-field-datetime-gap-to-8-hours
https://learn.microsoft.com/en-us/answers/questions/188584/different-time-is-returned-when-creating-sharepoin.html?childToView=446687#answer-446687
AB#9998
https://github.com/microsoftgraph/msgraph-sdk-java/issues/813