Re: difference in seconds between two formatted dates ...
On 12/18/23, Max Nikulin <manikulin@gmail.com> wrote:
> Timestamp format you have chosen is ambiguous.
>
> TZ=Europe/Berlin date -d '@1698539400' '+%Y%m%d%H%M%S'
> 20231029023000
>
> TZ=Europe/Berlin date -d '@1698543000' '+%Y%m%d%H%M%S'
> 20231029023000
>
> You had issues with setting time and timezone, so '+%s' may give
> incorrect results.
Hmm! and one hour difference is not detected, because of the way is
being parsed. Why would that happen? Why would %S be in the range
second (00..60), instead of (00..59)?:
seks00=1698539400; TZ=Europe/Berlin date -d '@1698539400' '+%Y%m%d%H%M%S'
seks02=1698543000; TZ=Europe/Berlin date -d '@1698543000' '+%Y%m%d%H%M%S'
diff_seks=$(( seks02 - seks00 ))
echo "// __ \$diff_seks: |$diff_seks|"
https://man7.org/linux/man-pages/man1/date.1.html
%Y year
%m month (01..12)
%d day of month (e.g., 01)
%H hour (00..23)
%M minute (00..59)
%S second (00..60)
~
C
Reply to: