display file modify date in "%Y/%m/%d %H:%M:%S".

adding compile time option to display file modification date as "%Y/%m/%d %H:%M:%S" in http directory indexing.
This commit is contained in:
Behnejad 2022-09-07 09:04:15 +04:30 committed by GitHub
parent 84de7437c6
commit ad50447ec6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -563,7 +563,19 @@ static void printdirentry(const char *name, void *userdata) {
} else {
mg_snprintf(sz, sizeof(sz), "%lld", (uint64_t) size);
}
#if defined(MG_HTTP_LOCALTIME)
char time_str[30];
struct tm * time_info = localtime(&t);
strftime(time_str, sizeof time_str, "%Y/%m/%d %H:%M:%S", time_info);
mg_snprintf(mod, sizeof(mod), "%s", time_str);
#elif defined(MG_HTTP_UTC)
char time_str[30];
struct tm * time_info = gmtime(&t);
strftime(time_str, sizeof time_str, "%Y/%m/%d %H:%M:%S", time_info);
mg_snprintf(mod, sizeof(mod), "%s", time_str);
#else
mg_snprintf(mod, sizeof(mod), "%ld", (unsigned long) t);
#endif
n = (int) mg_url_encode(name, strlen(name), path, sizeof(path));
mg_printf(d->c,
" <tr><td><a href=\"%.*s%s\">%s%s</a></td>"