Skip to Content
0
Jan 04, 2023 at 04:29 AM

[SAP CPI]: Timezone Offset in Groovy

459 Views Last edit Jan 04, 2023 at 04:31 AM 2 rev

Hi Experts,

I am getting the date stamp as (eg: 2022-12-05T11:17:02.693+01:00) and I need to format it in yyyyMMddHHmmssSSS.

The expected Output is: 20221205101702693

So I used the below groovy script and got the output as 20221205111702693.

import com.sap.gateway.ip.core.customdev.util.Message;
import groovy.json.*
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
def Message processData(Message message) {

        String mod_time = message.getProperty("PL_ModificationTime");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
        Date MOD = sdf.parse(mod_time);

        message.setProperty("ModificationTime", MOD.format("yyyyMMddHHmmssSSS"));

	return message;
}

Can anyone tell me how to offset it and get the desired output of 20221205101702693?

I tried with the below but no luck :(

  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");

Regards,

Pavan G