Using Groovy Scripts to read the date and time and reduce -5:30 hrs of date and time.
Read the input value in property name -ActivityStartDate
Example:
import com.sap.it.api.mapping.*;
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
def String customFunc(String arg1)
{
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
def currentTime= arg1;
LocalDateTime datetime = LocalDateTime.parse(currentTime,formatter);
datetime=datetime.minusHours(5).minusMinutes(30);
return datetime;
}
(OR)
import java.util.HashMap;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
def Message processData(Message message) {
//Body
def body = message.getBody();
//Properties
map = message.getProperties();
value = map.get("ActivityStartDate");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
def currentTime= value;
LocalDateTime datetime = LocalDateTime.parse(currentTime,formatter);
datetime=datetime.minusHours(5).minusMinutes(30);
message.setProperty("CurrentDate",datetime);
return message;
}
Input:
3:00 PM 09-04-2022
3:00 AM 09-04-2022
Output:
9:30 AM 09-04-2022
9:30 PM 08-04-2022
No comments:
Post a Comment