Minimal implementation of gmtime algorithm?

Does anyone know about a simple implementation of gmtime or ctime without taking into account the time zone, external dependencies and non-copyleft license (BSD / MIT / something protected by the company)? Preferably in C, but basically everything that gives me the algorithm in its minimal form will work.

I just need the seconds from "January 1, 1970 00:00:00", broken by year, day, month, hour, min, sec. And it's almost time to get home on Friday, so I feel a little lazy.

+4
source share
2 answers

Try newlib http://sourceware.org/newlib/ is a BSD license.

It is designed for embedded systems, so it tends to be quite small and simple.

Take a look at Docs -> Timefns to see if ctime or gmtime fits your needs.

+2
source

Cancel the algorithm that defines "Seconds from an era" from POSIX:

http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_15

 tm_sec + tm_min*60 + tm_hour*3600 + tm_yday*86400 + (tm_year-70)*31536000 + ((tm_year-69)/4)*86400 - ((tm_year-1)/100)*86400 + ((tm_year+299)/400)*86400 
+5
source

Source: https://habr.com/ru/post/1401913/


All Articles