Different time is returned when creating SharePoint List Item with datetime field by POST metohd with Graph API.

N Kohji 21 Reputation points
2020-12-07T08:17:27.807+00:00

When I post following request using the graph-explorer,

POST v1.0 /sites/mydomain.sharepoint.com,....,..../lists/..../items
{
    "fields": {
        "Title": "test7",
        // ...
        "_x7533__x8acb__x6642__x523b_": "2020-12-07T08:44:58.546Z",
        // ...
    }
}

I got following successful response. However, there is 8 hour gap between the request and the response. The field is of type Date and Time. As "Z" suffix represents, both timezone is UTC.

{
    // ...
    "fields": {
        // ...
        "_x7533__x8acb__x6642__x523b_": "2020-12-07T00:44:58Z",
        // ...
    }
}

Because my timezone is UTC+9(Tokyo), timezone doesn't seem to be the reason of the 8 hour gap.
How can I add a list item as requested without the mysterious time gap?

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
36,246 questions
{count} votes

2 additional answers

Sort by: Most helpful
  1. Vodolan Jan 1 Reputation point
    2021-06-22T09:02:06.363+00:00

    any progress? we face the same issue. called through java API.
    public static void createItem(GraphServiceClient graphClient, String siteId, String listId) {
    ListItem listItem = new ListItem();

            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
    
    0 comments No comments

  2. Vodolan Jan 1 Reputation point
    2021-06-22T09:41:54.943+00:00

    API ignores 'Z' char - UTC indicator. It looks like a bug )-:

    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"
    }
    }

    Request: "begin": "2000-01-01T00:00:00Z"
    Response: "begin": "1999-12-31T16:00:00Z"
    -8h

    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 ...

    0 comments No comments