try this:
Code:
#include <glib.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int GetTimeAsString(char* str, size_t str_len)
{
time_t t;
char* time_str;
tm *my_tm;
t = time(NULL);
my_tm = localtime(&t);
time_str = g_strdup_printf("%d/%02d/%02d %02d:%02d:%02d", my_tm->tm_year + 1900,
my_tm->tm_mon + 1,
my_tm->tm_mday,
my_tm->tm_hour,
my_tm->tm_min,
my_tm->tm_sec);
if (strlen(time_str) > (len - 1)) return -1;
else
{
memset(str, 0, strlen(time_str) + 1);
strcpy(str, time_str);
return 0;
}
}
haven't tried to compile it or test it or anything, but I use a function very similar to this in some of my code (this is actually the version with all my custom stuff stripped out), so it should get you to where you want to go.