convert epoch time to human readable without a dedicated function
Question
I'm writing a macro for slick-edit (with the C similar language slick-C)
As far as I found there are no time functions to help me convert epoch time (1321357827) to a human readable date and time
(if any of you knows how to do it in slick-C it's great, those of you who doesn't know it - assume C without time.h or any other libs)
Solution
In SE16 you'll find a whole class for date/time manipulation in se/datetime/DateTime.e.
In addition, the built-in function _time
has an option to return the epoch time.
You should find enough example code there.
And for the basic algorithm I found another SO question answered on this: Includes a link to gmtime source. From there you should be able to adapt to SlickEdit code.
OTHER TIPS
If you need only the time you could do:
sec_of_day = epoch % (24 * 60 * 60);
hour = sec_of_day / (60 * 60);
minute = sec_of_day % (60 * 60) / 60;
second = epoch % 60;
. This is of course not considering the timezone of your system.
If you need the date, you need to consider leap years.
EDIT: Warning: this code does not take into account leap seconds.