views:

35

answers:

2

I need to print this value as a time string to Mon 16-Aug-2010 06:24 format or something similar.

unsigned int t = 1281920090;
+2  A: 

That's actually a time_t not an unsigned int.

You can use ctime to generate a simple string in a similar format (or a combination of asctime and localtime or gmtime) or you can use strftime to specify the exact format you want.

Rup
isnt time_t just 'unsigned int' typedef'ed in time.h ?
kk
+4  A: 

You can use the functions gmtime and asctime as:

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

int main() {
        time_t timestamp = 1281920090;
        printf("%s", asctime(gmtime(&timestamp)));
        return 0;
}

Output:

$ gcc a.c && ./a.out
Mon Aug 16 00:54:50 2010
codaddict
thanks. this is what i needed.
kk