Skip to main content
Question

Help to convert an attribute that contains epoch time?

  • April 18, 2013
  • 5 replies
  • 146 views

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)
This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

5 replies

Forum|alt.badge.img+4
  • April 18, 2013
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.

takashi
Celebrity
  • April 18, 2013
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

takashi
Celebrity
  • April 19, 2013
Sorry, there are typos in my previous response: 'StringFormatter' --> 'DateFormatter'

  • Author
  • April 23, 2013

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


takashi
Celebrity
  • April 24, 2013
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