문제

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)

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top