Convert unix epoch to date and time

Post your questions and help other users.

Moderator: Martin

Post Reply
lueq
Posts: 25
Joined: 06 Feb 2016 00:15

Convert unix epoch to date and time

Post by lueq » 19 Feb 2016 14:33

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!

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Convert unix epoch to date and time

Post by Martin » 20 Feb 2016 11:13

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

lueq
Posts: 25
Joined: 06 Feb 2016 00:15

Re: Convert unix epoch to date and time

Post by lueq » 20 Feb 2016 18:30

Ah, it seems I have been overcomplicating this.

Thanks!

Post Reply