Skip to content

Instantly share code, notes, and snippets.

@adrianmoses
Last active December 11, 2015 22:39
Show Gist options
  • Select an option

  • Save adrianmoses/4671337 to your computer and use it in GitHub Desktop.

Select an option

Save adrianmoses/4671337 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <time.h>
#define TIME_SIZE 100
char * getcurrenttime(){
char *buffer = malloc(TIME_SIZE);
struct tm *ts;
size_t size;
time_t timestamp = time(NULL);
ts = localtime(&timestamp);
size = strftime(buffer, 32, "%a, %d %b %Y %T %z", ts);
buffer[size] = '\0';
return buffer;
}
int main(void){
char *current_time = getcurrenttime();
printf("%s\n", current_time);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment