qLibc
qtime.c File Reference

Time handling APIs. More...

Go to the source code of this file.

Functions

long qtime_current_milli (void)
 Returns the current time in milliseconds. More...
 
char * qtime_localtime_strf (char *buf, int size, time_t utctime, const char *format)
 Get custom formmatted local time string. More...
 
char * qtime_localtime_str (time_t utctime)
 Get local time string formatted like '02-Nov-2007 16:37:39 +0900'. More...
 
const char * qtime_localtime_staticstr (time_t utctime)
 Get local time string formatted like '02-Nov-2007 16:37:39 +0900'. More...
 
char * qtime_gmt_strf (char *buf, int size, time_t utctime, const char *format)
 Get custom formmatted GMT time string. More...
 
char * qtime_gmt_str (time_t utctime)
 Get GMT time string formatted like 'Wed, 11-Nov-2007 23:19:25 GMT'. More...
 
const char * qtime_gmt_staticstr (time_t utctime)
 Get GMT time string formatted like 'Wed, 11-Nov-2007 23:19:25 GMT'. More...
 
time_t qtime_parse_gmtstr (const char *gmtstr)
 This parses GMT/Timezone(+/-) formatted time sting like 'Sun, 04 May 2008 18:50:39 GMT', 'Mon, 05 May 2008 03:50:39 +0900' and returns as universal time. More...
 

Detailed Description

Time handling APIs.

Definition in file qtime.c.

Function Documentation

long qtime_current_milli ( void  )

Returns the current time in milliseconds.

Returns
current time in milliseconds.

Definition at line 49 of file qtime.c.

char* qtime_localtime_strf ( char *  buf,
int  size,
time_t  utctime,
const char *  format 
)

Get custom formmatted local time string.

Parameters
bufsave buffer
sizebuffer size
utctime0 for current time, universal time for specific time
formatformat for strftime()
Returns
string pointer of buf
char *timestr = qtime_localtime_strf(0, "%H:%M:%S"); // HH:MM:SS
free(timestr);
char *timestr = qtime_localtime_strf(0, "%Y%m%d%H%M%S"); // YYMMDDhhmmss
free(timestr);

Definition at line 73 of file qtime.c.

char* qtime_localtime_str ( time_t  utctime)

Get local time string formatted like '02-Nov-2007 16:37:39 +0900'.

Parameters
utctime0 for current time, universal time for specific time
Returns
mallocked string pointer of time string
char *timestr;
timestr = qtime_localtime_str(0); // now
free(timestr);
timestr = qtime_localtime_str(time(NULL)); // same as above
free(timestr);
timestr = qtime_localtime_str(time(NULL) - 86400)); // 1 day before
free(timestr);

Definition at line 103 of file qtime.c.

const char* qtime_localtime_staticstr ( time_t  utctime)

Get local time string formatted like '02-Nov-2007 16:37:39 +0900'.

Parameters
utctime0 for current time, universal time for specific time
Returns
internal static string pointer of time string
printf("%s", qtime_localtime_staticstr(0)); // now
printf("%s", qtime_localtime_staticstr(time(NULL) + 86400)); // 1 day later

Definition at line 122 of file qtime.c.

char* qtime_gmt_strf ( char *  buf,
int  size,
time_t  utctime,
const char *  format 
)

Get custom formmatted GMT time string.

Parameters
bufsave buffer
sizebuffer size
utctime0 for current time, universal time for specific time
formatformat for strftime()
Returns
string pointer of buf
char timestr[8+1];
qtime_gmt_strf(buf, sizeof(buf), 0, "%H:%M:%S"); // HH:MM:SS

Definition at line 145 of file qtime.c.

char* qtime_gmt_str ( time_t  utctime)

Get GMT time string formatted like 'Wed, 11-Nov-2007 23:19:25 GMT'.

Parameters
utctime0 for current time, universal time for specific time
Returns
malloced string pointer which points GMT time string.
char *timestr;
timestr = qtime_gmt_str(0); // now
free(timestr);
timestr = qtime_gmt_str(time(NULL)); // same as above
free(timestr);
timestr = qtime_gmt_str(time(NULL) - 86400)); // 1 day before
free(timestr);

Definition at line 171 of file qtime.c.

const char* qtime_gmt_staticstr ( time_t  utctime)

Get GMT time string formatted like 'Wed, 11-Nov-2007 23:19:25 GMT'.

Parameters
utctime0 for current time, universal time for specific time
Returns
internal static string pointer which points GMT time string.
printf("%s", qtime_gmt_staticstr(0)); // now
printf("%s", qtime_gmt_staticstr(time(NULL) + 86400)); // 1 day later

Definition at line 191 of file qtime.c.

time_t qtime_parse_gmtstr ( const char *  gmtstr)

This parses GMT/Timezone(+/-) formatted time sting like 'Sun, 04 May 2008 18:50:39 GMT', 'Mon, 05 May 2008 03:50:39 +0900' and returns as universal time.

Parameters
gmtstrGMT/Timezone(+/-) formatted time string
Returns
universal time(UTC). in case of conversion error, returns -1.
time_t t = time(NULL);
char *s = qtime_parse_gmtstr(t);
printf("%d\n", t);
printf("%s\n", s);
printf("%d\n", qtime_parse_gmtstr(s)); // this must be same as t
free(s);

Definition at line 217 of file qtime.c.