cancel
Showing results for 
Search instead for 
Did you mean: 

Need help in UTC Date and Time format

0 Kudos

Hi All,

Need some mapping logic to display UTC date in one field and UTC Time in another field. Please let me know how to implement logic in PO .

Thanks in advance,

Jeevitha

Accepted Solutions (0)

Answers (1)

Answers (1)

yogananda
Product and Topic Expert
Product and Topic Expert
0 Kudos

jeevi3

You can use a user-defined function (UDF) to convert the UTC date and time into separate fields

1. Here is an example of a UDF that converts a UTC date into a separate field:
try {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
    Date date = sdf.parse(var1[0],new ParsePosition(0));
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.add(Calendar.DATE, var2[0]);
    date = cal.getTime();
    String output = sdf.format(date);
    result.addValue(output);
} catch (Exception e) {
    throw new StreamTransformationException(e.getMessage());
}

This UDF takes two input parameters: the UTC date and the number of days to add or subtract from the date. It then converts the UTC date into a Java Date object, adds or subtracts the specified number of days, and formats the resulting date as a string in the format yyyyMMdd. The resulting string is then added to the output field.

You can modify this UDF to convert the UTC time into a separate field by using the SimpleDateFormat class to format the time as a string in the desired format.

I hope this helps!