-
Notifications
You must be signed in to change notification settings - Fork 594
Closed
Description
At least on Linux (glibc at least, musl as well AFAICT), TZ= forces UTC timezone, not the local timezone. That doesn't seem to be documented anywhere though...
Example C code:
#include <stdio.h>
#include <time.h>
int main(int argc, char *argv[]) {
char outstr[200];
time_t t;
struct tm *tmp;
t = time(NULL);
tmp = localtime(&t);
strftime(outstr, sizeof(outstr), "%c %Z", tmp);
puts(outstr);
}
Example output. Setting TZ= is equivalent to setting TZ=UTC:
$ ./test
Sat Apr 5 14:53:55 2025 CEST << that's /etc/localtime timezone
$ TZ= ./test
Sat Apr 5 12:53:57 2025 UTC
$ TZ=UTC ./test
Sat Apr 5 12:54:05 2025 UTC
Rust test program:
use chrono::Local;
fn main() {
println!("{}", Local::now());
}
$ cargo run
2025-04-05 14:58:04.069014727 +02:00
$ TZ= cargo run
2025-04-05 14:58:06.276775336 +02:00 <<< This should probably be +02:00
$ TZ=UTC cargo run
2025-04-05 12:58:09.002152546 +00:00
This causes issues in uutils/coreutils: uutils/coreutils#7498
Metadata
Metadata
Assignees
Labels
No labels