One of the fields in the payload to workflow is a date field and it is in format of unix timestamp (in milliseconds). I want to find a way to convert it to a date string in format of YYYYMMDD. I tried the date functions in workflow transform however not lucky.
long unix_seconds = 1372339860;
//convert seconds to milliseconds
Date date = new Date(unix_seconds*1000L);
// format of the date
SimpleDateFormat jdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
jdf.setTimeZone(TimeZone.getTimeZone("GMT-4"));
String java_date = jdf.format(date);
I think this is a workflow related ask.
There’s a few ways to do this
EpochDate Time is milliseconds since 1970, therefore you can use a transformer to increment a date starting from 1970-01-01 and add the milliseconds, like below, but passing the epoch time rather than hardcoding like I did in the screenshot
If you ever need to go the opposite direction then CalculateDateDifference can be used, to calculate the number of seconds between 1970-01-01 and the datetime, then multiply up to get the milliseconds value with another transformer.
Some people might find this easier in a FlowService so just for completeness, I attached a couple of FlowService samples exported from wm.io integration to convert an Epoch date to Excel formatted date (the excel format date always blows my mind ), and also a convert date time to Epoch.
Just remember sometime epoch has two flavours to content with just to make life difficult - seconds or milliseconds
Currently Java Services aren’t avail in webmethods.io(hint: we are working on this though)
You can achieve this in FlowService even without a Java Service though with some creative use of the date functions