cancel
Showing results for 
Search instead for 
Did you mean: 

Convert Unix / EPOCH time stamp into simple date

gabe_f
Explorer
0 Kudos
3,032

Hi All,

I have an Odata response in JSON format where the invoice date is passed as a timestamp. The standard JSON to XML convert function works well except the date.

<CGROSS_AMOUNT_CU>USD</CGROSS_AMOUNT_CU><br><CINVOICE_DATE>/Date(1645660800000)/</CINVOICE_DATE><br><CINVOICE_UUID>028</CINVOICE_UUID>

I have a requirement to covert /Date(1645660800000)/ to yyyy-MM-dd for an XML mapping. The date trans function within the message mapping didn't covert correctly. What is the easiest method? Thanks.

View Entire Topic
YuvrajKarwar
Explorer
0 Kudos

Hello Gabrielu.

Check below groovy script to convert EPOCH time stamp, it will directly give you date. You can manipulate time zone as per your requirment.

import com.sap.gateway.ip.core.customdev.util.Message;
    import java.util.*;
    import java.time.Instant;
    import java.time.LocalDate;
    import java.time.ZoneId;
    import java.time.ZonedDateTime;

    
    def Message processData(Message message) {
        map = message.getProperties();
        Instant i=Instant.ofEpochMilli(1645660800000)
        ZonedDateTime z=i.atZone(ZoneId.of("Asia/Calcutta"))
        LocalDate date=z.toLocalDate()
        message.setProperty("CINVOICE_DATE", date);
        return message;
        }
gabe_f
Explorer
0 Kudos

Thanks. But the script didn't convert though.