I think you’re reinventing the wheel here. All that is needed to get the date in that format is `/bin/date +%Y%m%d%H%M%S` which works on most *nix systems. All you are doing the “+%Y”… is just reformatting the output of the date command.




John Yoder


From: linux-fbdev-users-bounces@lists.sourceforge.net [mailto:linux-fbdev-users-bounces@lists.sourceforge.net] On Behalf Of Bui Sy Phong
Sent: Tuesday, September 19, 2006 8:49 AM
To: linux-fbdev-users@lists.sourceforge.net
Subject: [Linux-fbdev-users] Question on time system


Hi everybody,

I know that i post this question in a wrong place, but if someone can help me to resolve it, it will be wonderful for me.

In fact, i must write a little program wich diplay the local time of system on this format (a string) : Year/Mount/Day/Hour/Minute/Second , like : 20060919164421

So, i can get the number of second since : 01/01/1970 at 00:00:00 but i dont know how to convert this to a string like above.

Here's my little code to get the number of second since 01/01/1970 :

#include < stdio.h>
#include <time.h>
#include <stdint.h>

int main(void)
    time_t result;
    result = time(NULL);
    printf("%s%ju secs since January 1, 1970 0:00 UTC\n",
    unsigned int seconds = (uintmax_t)result;
    printf("%u\n", seconds);


I know that i must use strftime() to convert but i dont know how.

So, i post this question here. And waiting for your helpful.

Thanks very much.

P/S : I dont care about Timezone (it's always in UTC - GMT)