Skip to content

Instantly share code, notes, and snippets.

@deep5050
Last active April 16, 2020 09:54
Show Gist options
  • Save deep5050/948351469bbb7cf2cf5ac3dea502724d to your computer and use it in GitHub Desktop.
Save deep5050/948351469bbb7cf2cf5ac3dea502724d to your computer and use it in GitHub Desktop.
human readable timestamp in c
char *timestamp()
{
struct tm *local;
time_t t = time(NULL);
char *str;
/* Get the localtime */
local = localtime(&t);
str = asctime(local);
int i = 0;
int len = strlen(str) + 1;
for (i = 0; i < len; i++)
{
if (str[i] == '\n')
{
/* Move all the char following the char "\n" by one to the left. */
strncpy(&str[i], &str[i + 1], len - i);
}
}
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment