4 ms·
"Mon, 20 Jan 2025 06:07:07 GMT" I thought the default output of date(1), with TZ unset, is something like Mon Jan 20 06:07:07 UTC 2025 That's the busybox
by 1vuio0pswjnm7 2y ago
"Mon, 20 Jan 2025 06:07:07 GMT"
I thought the default output of date(1), with TZ unset, is something like
Mon Jan 20 06:07:07 UTC 2025
That's the busybox default anyway
- johnisgood 2y agoWell, `Mon Jan 20 06:07:07 UTC 2025` does not match `fmt` in the code. My input matches the format string exactly, which is why it works. You could use `"%a %b %d %H:%M:%S %Z %Y"` for `fmt` (which is indeed the default for `date`) and it would work with yours. Both results in the same timestamp.
- 1vuio0pswjnm7 2y agoIf I use "UTC" it works. For example, date.l: int fileno (FILE *); FILE *f; int printf(const char *__restrict, ...); #include <time.h> char *strptime(const char *s, const char *f, struct tm *tm); struct tm t; a (Mon|Tue|Wed|Thu|Fri|Sat|Sun) b (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) d [0-2][0-9]|3[01] H [0-2][0-9] M [0-5][0-9] S [0-5][0-9] Y [1-9][0-9][0-9][0-9] %option nounput noinput noyywrap %% {a}[ ]{b}[ ]{d}[ ]{H}:{M}:{S}[ ]UTC[ ]{Y} { strptime(yytext,"%a %b %d %H:%M:%S UTC %Y",&t); printf("%ld\n",mktime(&t)); } .|\n %% int main(){yylex();exit(0);} flex -8Cem date.l cc -O3 -std=c89 -W -Wall -pipe lex.yy.c -static -s -o yydate date|yydate This works for me. No need for timegm(). But if I substitute %Z or %z for "UTC" in strptime() above then this does not work. Fun fact: strptime() can make timestamps for dates that do not exist on any calandar. echo "Thu Jun 31 01:59:26 UTC 2024"|yydate