Skip to content

Instantly share code, notes, and snippets.

@hhc0null
Created December 18, 2015 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hhc0null/00d812af52a0ac42ed7f to your computer and use it in GitHub Desktop.
Save hhc0null/00d812af52a0ac42ed7f to your computer and use it in GitHub Desktop.
myon
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#define TIME_PREFIX_SIZE 8 // "YYYYmmdd"
int main()
{
struct tm *current_tm;
time_t current_time;
char buf[TIME_PREFIX_SIZE] = {};
current_time = time(NULL);
current_tm = localtime(&current_time);
assert(TIME_PREFIX_SIZE == strftime(buf, TIME_PREFIX_SIZE + 1 /* contains null byte */, "%Y%m%d", current_tm));
printf("%d - ", strlen(buf));
puts(buf);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment