GraphAPI Create SharePoint ListItem, timestamp format ignored

Jan Vodolan 1 Reputation point

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:

Content-Type: application/json  
Authorization: Bearer token  
  "fields": {  
    "Title": "any title",  
    "timestamp": "2021-06-22T12:00:00"  

Sample code:

Instant now = Instant  
     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  
     System.out.println("createdDateTime=" +li.createdDateTime);  

createDateTime= 2021-06-22T01:58:02Z

HTTP requests examples:
Request: "begin": "2000-01-01T00:00:00Z"
Response: "begin": "1999-12-31T16:00:00Z"

Request: "begin": "2021-06-22T12:00:00+02:00"
Response: "begin": "2021-06-22T03:00:00Z"

Request: "begin": "2021-06-22T12:00:00Z"
Response: "begin": "2021-06-22T05:00:00Z"

Request: "begin": "2021-06-22T12:00:00"
Response: "begin": "2021-06-22T12:00:00Z"
Ignores UTC - Z char ...

See also:

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,557 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,663 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MichaelHan-MSFT 18,016 Reputation points

    Hi @Jan Vodolan ,

    I used to have similar issue as yours when creating listitem with DateTime field. And I found that date field in the response returned is displayed incorrectly. After creating the list item, you should use Get listItem endpoint to check the date field:

    I opened this issue in github a few days ago:

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.