Last active
April 16, 2020 09:54
-
-
Save deep5050/948351469bbb7cf2cf5ac3dea502724d to your computer and use it in GitHub Desktop.
human readable timestamp in c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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