Since you've got a time_t
value, you can use localtime()
and strftime()
:
#include <time.h>
#include <stdio.h>
int main(void)
{
time_t t = time(0);
struct tm *lt = localtime(&t);
char buffer[20];
strftime(buffer, sizeof(buffer), "%a %b %d %Y", lt);
puts(buffer);
return(0);
}
Alternatively, if you feel you must use ctime()
, then:
#include <time.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
time_t t = time(0);
char buffer[20];
char *str = ctime(&t);
memmove(&buffer[0], &str[0], 11);
memmove(&buffer[11], &str[20], 4);
buffer[15] = '\0';
puts(buffer);
return(0);
}