Page 1 of 1

Convert unix epoch to date and time

Posted: 19 Feb 2016 14:33
by lueq
Is there a simple way in AM script to convert a time in the Unix epoch format to a date and time?
I don't see this option in the date formats.

sqlite can take care of the conversion, but it seems a content provider can only return the raw value?

Thanks!

Re: Convert unix epoch to date and time

Posted: 20 Feb 2016 11:13
by Martin
You can use {variable,dateformat,dd.MM.yyyy HH:mm:ss} to format milliseconds since 1970 to a string. You can also use {variable*1000,dateformat,dd.MM.yyyy HH:mm:ss} if you have the unix epoch in seconds. The content provider most likely contains milliseconds.

You can use a script to convert a string like "20.02.2016 13:00" to the milliseconds since 1970:

Code: Select all

variable = "20.02.2016 13:00";
datetime = getDate(variable, "dd.MM.yyyy HH:mm");
Also check the help page of action Script, section String Inline Expressions and Date Format Pattern

Regards,
Martin

Re: Convert unix epoch to date and time

Posted: 20 Feb 2016 18:30
by lueq
Ah, it seems I have been overcomplicating this.

Thanks!