If I enter date +"%Y/%m/%d %H:%M" -d "20200819T1234"
the expected output is 2020/08/19 12:34
when in I actually get 2020/08/19 02:34
that is, exactly 10 hours less. Could someone explain to me why this happens?
At the moment I manage with + 10 hours
at the end of the command, but I don’t think this is normal. The time zone set on the server is -03
so I am very confused.
This happens in both Ubuntu 16 and Debian 10
2
Answers
Your format is mismatch with the time string: try
2020/08/19 12:34
The GNU code for parsing dates (
parse_datetime2
) has this table embedded within it that provides the reason why you’re getting the incorrect time (trimmed for conciseness):And, indeed, if you run
date
in debug mode, you can see what’s happening (output trimmed for conciseness):Most letters apply a timezone offset based on military timezones, hence the
T
that would normally be used to separate date and time in ISO format is being handled differently here, as specifyingUTC+7
, explaining the ten-hour difference between that and your server atUTC-3
.The bottom line is that you need to use an input format that’s acceptable to
date
. That’s as simple as (in this case) replacing the T with a space, as per the following transcript: