Skip to Content
0

Converting Date format from Systemdate to Epoch/UNIX timestamp(1513774271000) in SAP PI?

Dec 20, 2017 at 01:22 PM

284

avatar image

Hi Experts,

I have a requirement in one of the mapping, Date is coming from the Source system as "sy-datum" let say for example "20/12/2017 12/51/11", this date format would be convert into Json timestamp like /Date(1513774271000)/.

I am not aware how to normal datetime stamp get converted into 1513774271000(Epoch timestamp).

Can anybody help to write UDF for this?

Thank you, Raghava.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Raghava B Dec 29, 2017 at 09:56 AM
0

Thank you Evigeny for helping.

https://answers.sap.com/comments/392403/view.html

Share
10 |10000 characters needed characters left characters exceeded
Evgeniy Kolmakov Dec 21, 2017 at 12:04 PM
0

Hi Raghava!

String dateString = "20/12/2017 12:51:11";
long datetime = (new SimpleDateFormat("dd/MM/yyyy HH:mm:ss")).parse(dateString).getTime();

Regards, Evgeniy

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Adding to what Evgeniy has already provided, you may need to multiply by 1000, if the JSON timestamp is in milliseconds.

0
Raghava B Dec 28, 2017 at 09:46 AM
0

Hi Evgeniy,

Thank you for a quick reply, I have tried to implement the code as you suggested. But I am getting an error.

Please the find the code

Please suggest.


error.png (16.2 kB)
code.png (11.0 kB)
Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hi Raghava!

Regards, Evgeniy.

udf-timestamp.png (20.6 kB)
0

Thanks, Evgeniy. This code is perfectly working fine.

0