Page 1 of 1

unix to date/time

Posted: 04 Feb 2018 12:59
by schuster666
Hi,
Howto convert this string in to Date?
1515769353

Source is the Nokia Health Api.

Once AM says "can not convert value 'null' to number"
next time i tried
"Unparseable date".

What's the right syntext?

Tried:
getDate(variable, "yyyy.MM.dd");
getDate(variable,dateformat,"dd.MM.yyyy HH:mm:ss");

With and without multiplication *1000 to convert it to ms.
Also tried "toNumber", no go.

Anyone?


EDIT:

OK, brrrrrrr
think i have do the multiplication with 100 instead of "1000".

time=1515769353*1000;
time_formatted = "{time, dateformat, dd.MM.yyyy HH:mm:ss}";

this do the job.

Re: unix to date/time

Posted: 04 Feb 2018 17:30
by Desmanto
The time_formatted you get after using your code above is a string, not a datetime. You can't add it as usual. Be careful of logic flaw trap when dealing with time in string format. It is preferred to always store time in the datetime format, and convert to string only at the last step before displaying it.

1515769353 is seconds, means just use s in the checking string.

Code: Select all

variable = 1515769353;
time = getDate(variable, "s");
To use miliseconds, use uppercase S.

I don't know if the API give you the correct timezone. If it gives based on UTC, you can add/minus your timezone hours to it. Example for UTC+7, add 7 hours.

Code: Select all

variable = 1515769353;
timez = addHours(getDate(variable, "s"), 7);
While if you use time_formatted in string format, the addHours() will throw error exception.