Convert Epoch to a Time
| Definition: | fromEpochToTime(epoch: int) → datetime.time
|
| Description: | Converts an epoch value in milliseconds to a Python time object. The value is ingested in Hevo as a string. However, it is loaded to the Destination as a timestamp object, as indicated by the timestamp datatype in the Transformation output.Note: The attributes of a time object include: hour, minute, and second. Example: datetime.time(15, 30, 45, 500000)
|
| Parameters: | epoch: The timestamp value in milliseconds to convert. |
| Returns: | The converted value as a time object. |
The following script takes an epoch value as an argument and returns a time object.
from io.hevo.api import Event
from io.hevo.api import TimeUtils
def transform(event):
# Get properties from the Event #
epoch = <value in milliseconds>
<dateObject> = TimeUtils.fromEpochToTime(<epoch>)
return event
Sample Transformation
The following script transforms the epoch value (in milliseconds) stored in the millis field into a time object by utilizing the fromEpochToTime(int: epoch) method, and returns the result in the neweventtime field.
from io.hevo.api import Event
from io.hevo.api import TimeUtils
def transform(event):
# Get properties from the Event #
eventName = event.getEventName()
properties = event.getProperties()
epoch = properties["millis"]
properties['neweventtime'] = TimeUtils.fromEpochToTime(epoch)
return event
Sample Output
The epoch time 1672987516206 is converted to a time object with value 06:45:16 and added in the neweventtime field.

Last updated on Jun 30, 2023