cancel
Showing results for 
Search instead for 
Did you mean: 

Erroneous JSON-Timestamps?

Former Member
0 Kudos

Dear fellow developers,

I developed an OData service which contains entity types with Edm.DateTime properties. Using that service I receive erroneous results for timestamps when requesting JSON responses, which differ from the result received when requesting XML.

Did anyone of you ever experience that?

Example request:

..._SRV/MaintenanceNotifications?$filter=ChangeTimestamp ge datetime'2015-07-10T09:00:00'

XML response:

...<d:ChangeTimesamp>2015-07-14T09:22:48</(d:ChangeTimesamp>

JSON response (request sent with header Accept = application/json):

..."ChangeTimestamp" : "\/Date(1436865768000)\/"...

The timestamp from the JSON response corresponds to 2015-07-14 at 11:22:48, which is 2 hours ahead of the value in the XML response.

2 hours is also the time zone difference between UTC and CET summertime. System time zone and user time zone are both set to CET.

However, that should not make a difference, as XML responses are already correct?!

The System is on NetWeaver 7.4 with SAP_GWFND 740 SP 8.

Thank you for any helpful hints,

best regards,

Ringo

Message was edited by: Ringo Liebscher - added missing example request and responses.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

As you implicitly mentioned right the DateTime in JSON is the number of milliseconds since January 1st 1970 00:00:00.000.

But that point in time relates to UTC!

DateTime in XML is, as specified: Without a trailing Z at the timestamp the timestamp means system time zone, otherwise ZULU (=UTC) time.

Its different in OData/JSON: Here a timestamp is always UTC and its up to the FrontEnd-Dev to implement the timezone-adaption. E.g. get the local time zone from OS (or browser) and adjust the timestamp with JavaScript.

Greets

Silvio

Former Member
0 Kudos

Hi Silvio,

the way you described the processing of JSON timestamps is exactly what I expected: I wish to be in control of time zone conversions. Unfortunately, I am not in control and outgoing timestamp values are automatically changed after my method in the data provider extension class is finished, in my case they are decreased by two hours.

Setting the user time zone to UTC does not change the result. I am curious whether changing the system time zone would have an effect, but I wouldn´t do that in a running system.

The problem does not only occur in responses, but also in the interpretation of DateTime values in request bodies when creating or updating entities. In that case, the incoming timestamps are increased by two hours. However, in that case I could solve it by passing values in the format "YYYY-MM-DDTHH:MM:SS" instead of a milliseconds timestamp.

Setting the property type to Edm.DateTimeOffset does not change the result.

It´s very unlikely that I´m the only one to have that issue - nobody else worked with JSON timestamps in SP 8?