cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Date Epoch Example

aerthal
Former Employee

An epoch date is either the number of seconds or milliseconds since 1 January 1970 00:00:00 UTC. UNIX and other applications use seconds, while JavaScript uses milliseconds. SnapLogic uses JavaScript as its scripting language, so the epoch date is internally stored as milliseconds since epoch.

In the example below, we are passing in the date in seconds since epoch.

1 - Set a project parameter. In my example, I have โ€œdateEpochโ€ set to 1472799302.
2 - Use the following formula in a mapper snap:
Date.parse(Date.parse(1000*_dateEpoch).toString()).toLocaleDateTimeString(โ€˜{โ€œtimeZoneโ€:โ€œAmerica/Chicagoโ€, โ€œformatโ€:โ€œMM-dd-yyyy HH:mm:ssโ€}โ€™)

This returns a value of: 09-02-2016 01:55:02

Further examples:

Date.parse(1000*_dateEpoch) = โ€œ2016-09-02T06:55:02.000 Etc/UTCโ€

Date.parse(1000*_dateEpoch).toString() = โ€œ2016-09-02T06:55:02.000Zโ€

date test epoch_2017_02_28.slp (4.6 KB)

1 REPLY 1

aakumar
New Contributor III

Thanks for providing this example to convert epoch to date.

Do you have an example to convert date to epoch ?