Share

Convert Epoch Time to a Date

Definition: fromEpochToDate(epoch: int) → datetime.date
Description: Converts an epoch value in milliseconds to a Python date object in timestamp format.
Parameters: epoch: The timestamp value in milliseconds to convert.
Returns: The converted value as a date object.

The following script takes an epoch value as an argument and returns a date object.

from io.hevo.api import Event
from io.hevo.api import TimeUtils


def transform(event):

    # Get properties from the Event #
    <epoch> = <milliseconds_value>
    <date_object> = TimeUtils.fromEpochToDate(<epoch>)
    return <newEvent>

Sample Transformation

The following script transforms the epoch time (in milliseconds) stored in the millis field into a date object by utilizing the fromEpochToDate(int: epoch) method, and returns the result in the newdateobject 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['newdateobject'] = TimeUtils.fromEpochToDate(epoch)
    return event

Sample Output

The epoch time 1672986820000 is converted to a date object with value 1672963200000 and displayed in the newdateobject field.

Create Events


Last updated on Jun 30, 2023

Tell us what went wrong

Skip to the section