Skip to main content
Hi everyone, can someone show me how to take an incoming attribute that contains epoch time value and convert it to a standard date/time?

 

For example, one of my incoming records contains the attribute  "xtime" and it's equal to "1366274499.543"

 

Thanks guys, I'm trying to use the "date formatter", but can't get it to work.

 

Steve

 

(FME Desktop 2012)
The DateFormatter in FME 2013 can allow you to specify the source datetime format e.g. %s for Epoch. 

 

 

I don't believe theres a simple solution to converting from epoch to a date in FME 2012. But a few ExpressionEvaluators and a StringConcatenator could potentially perform it.
Hi Steve,

 

 

If StringFormatter doesn't work in your FME version, using PythonCaller would be a solution. An example script is:   import fmeobjects import time   def convertEpochTime(feature):     # Get the epoch time value.     xtime = float(feature.getAttribute('xtime'))          # Convert the epoch time to a time structure.     # If you need a local time, use 'localtime' instead of 'gmtime'.      t = time.gmtime(xtime)          # Get a formatted datetime string.     datetime = time.strftime('%Y-%m-%d %H:%M:%S', t)     feature.setAttribute('_datetime', datetime)          # Get elements of datetime individually, if you need.     feature.setAttribute('_year', t.tm_year)     feature.setAttribute('_month', t.tm_mon)     feature.setAttribute('_day', t.tm_mday)     feature.setAttribute('_hour', t.tm_hour)     feature.setAttribute('_minute', t.tm_min)     feature.setAttribute('_second', t.tm_sec)   In addition, when using StringFormatter of FME 2013 to format an epoch time, the transformer assumes input epoch time is an integer value, so you should round 'xtime' by AttributeRounder beforehand.

 

 

Takashi
Sorry, there are typos in my previous response: 'StringFormatter' --> 'DateFormatter'

Thanks for the input and suggestions!

 

Takashi, can you tell me what I should be using in my FME PythonCaller transformer as the 'Entry Point' value?

 

I'm not very skilled in Python...

 

Thanks for any help

Steve


Hi Steve,

 

 

'Entry Point' parameter indicates the name of a function / class which you want to use. If you use my example script without changing function name, set 'convertEpochTime' (this is the function name) to this parameter.

 

In addition, if you set new attributes to features in the script , set those  names (e.g. _datetime, _year... etc. in my example) to 'Attribute To Expose' parameter to expose them.

 

 

Takashi 

Reply