cancel
Showing results for 
Search instead for 
Did you mean: 

UDF for converting EPOCH timestamp to Date

Former Member
0 Kudos

Hi Experts,

Dynamically fetching Source time stamp from SFTP sender adapter using ASMA. It's giving me EPOCH time stamp.

MTimehttp://sap.com/xi/XI/System1475028600

Please help me to write UDF for converting this timestamp to Date GMT+1:00

Many Thanks

Accepted Solutions (1)

Accepted Solutions (1)

former_member182412
Active Contributor
0 Kudos

Hi Tapasya,

Use below UDF.

Execution Type: Single Values


public String epochToDate(String epoch, Container container) throws StreamTransformationException {

  SimpleDateFormat dateFormat = new SimpleDateFormat();

  dateFormat.setTimeZone(TimeZone.getTimeZone("GMT+1"));

  return dateFormat.format(new Date(Long.parseLong(epoch)));

  }

Test:

Regards,

Praveen.

Former Member
0 Kudos

Thanks Praveen.

But expected output is 9/28/2016,3:10:00 AM

0 Kudos

Hi Tapasya,

Update one line,

SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy ',' hh:mm:ss a");

Regards,

Ajinkya

former_member182412
Active Contributor
0 Kudos

Hi Tapasya,

I think your epoch time is seconds so we need to multiply by 1000 to get the mills seconds.

Use below UDF:


public String epochToDate(String epoch, Container container) throws StreamTransformationException {

  SimpleDateFormat dateFormat = new SimpleDateFormat();

  dateFormat.setTimeZone(TimeZone.getTimeZone("GMT+1"));

  return dateFormat.format(new Date(Long.parseLong(epoch) * 1000));

  }

Test:

Regards,

Praveen.

Answers (1)

Answers (1)

former_member818616
Discoverer
0 Kudos

Hi Tapasya,

My requirement is to convert Idoc date and time to EPOCH.

Do we have any UDF available for this?

Thanks in Advance.

Regards,

Imran