diff --git a/docs/cmdline-opts/write-out.md b/docs/cmdline-opts/write-out.md
index 4bef99e0d3..4f2f99dc4d 100644
--- a/docs/cmdline-opts/write-out.md
+++ b/docs/cmdline-opts/write-out.md
@@ -532,4 +532,4 @@ from UTC). As time is always UTC, this outputs `+0000`.
## `%Z`
-The timezone name, meaning `UTC`.
+The timezone name. For some reason `GMT`.
diff --git a/src/tool_writeout.c b/src/tool_writeout.c
index 10a6032b45..cbe0d50231 100644
--- a/src/tool_writeout.c
+++ b/src/tool_writeout.c
@@ -584,13 +584,18 @@ static const char *outtime(const char *ptr, /* %time{ ... */
curlx_dyn_init(&format, 1024);
/* insert sub-seconds for %f */
+ /* insert +0000 for %z because it is otherwise not portable */
for(i = 0; !result && i < vlen; i++) {
- if((i < vlen - 1) && ptr[i] == '%' && ptr[i + 1] == 'f') {
- result = curlx_dyn_addf(&format, "%06u", usecs);
+ if((i < vlen - 1) && ptr[i] == '%' &&
+ ((ptr[i + 1] == 'f') || (ptr[i + 1] == 'z'))) {
+ if(ptr[i + 1] == 'f')
+ result = curlx_dyn_addf(&format, "%06u", usecs);
+ else
+ result = curlx_dyn_addn(&format, "+0000", 5);
i++;
- continue;
}
- result = curlx_dyn_addn(&format, &ptr[i], 1);
+ else
+ result = curlx_dyn_addn(&format, &ptr[i], 1);
}
if(!result) {
/* !checksrc! disable BANNEDFUNC 1 */
diff --git a/tests/data/test1981 b/tests/data/test1981
index 47fc7ec17a..cfd04b6540 100644
--- a/tests/data/test1981
+++ b/tests/data/test1981
@@ -38,10 +38,10 @@ http
Debug
-CURL_TIME=1754037100
+CURL_TIME=1754037103
-http://%HOSTIP:%HTTPPORT/%TESTNUMBER --write-out='Time: %time{%d/%b/%Y %H:%M:%S.%f %z}\n' -s -o %LOGDIR/dump
+http://%HOSTIP:%HTTPPORT/%TESTNUMBER --write-out='Time: %time{%d/%b/%Y %H:%M:%S.%f %z %Z}\n' -s -o %LOGDIR/dump
@@ -56,7 +56,7 @@ Accept: */*
-Time: 01/Aug/2025 08:31:40.037100 +0000
+Time: 01/Aug/2025 08:31:43.037103 +0000 GMT