On 3/23/23, Albretch Mueller <lbrt...@gmail.com> wrote: > I am using this (yes, visually cr@ppy ;-)) code snippet to set back > the time 5 hours. hwclock tells me it worked fine but the terminal > windows opened before and after running hwclock still give me the > "old" time setting? > > _HRS_PM=-5 > > ### > # > https://stackoverflow.com/questions/1092631/get-current-time-in-seconds-since-the-epoch-on-linux-bash > _DTS=$(date +%s) > echo "// __ \$_DTS: |${_DTS}|"; > _DTF=$(date --date @${_DTS}) > echo "// __ \$_DTF: |${_DTF}|"; > > _NEW_DTS=$((_DTS+3600*_HRS_PM)) > echo "// __ \$_NEW_DTS: |${_NEW_DTS}|"; > > # Convert the number of seconds back to date > _NEW_DTF=$(date --date @${_NEW_DTS}) > echo "// __ \$_NEW_DTF: |${_NEW_DTF}|"; > > which hwclock > > sudo hwclock --show > sudo hwclock --debug --set --date "${_NEW_DTF}" > sudo hwclock --show > > date > > // __ $_DTS: |1679606975| > // __ $_DTF: |Thu 23 Mar 2023 09:29:35 PM UTC| > // __ $_NEW_DTS: |1679588975| > // __ $_NEW_DTF: |Thu 23 Mar 2023 04:29:35 PM UTC| > hwclock from util-linux 2.36.1 > Thu 23 Mar 2023 09:29:35 PM UTC > $ sudo hwclock --show > 2023-03-23 16:30:23.685781+00:00 > $ date > Thu 23 Mar 2023 09:31:40 PM UTC
I left all the above because I didn't know where to safely snip. I just battled this topic a couple months ago but can't remember which operating system. It was fixed INSTANTLY by creating /etc/adjtime (if it doesn't already exist) then entering the following: 0.0 0 0.0 0 UTC Once saved, it takes just a few seconds then, BAM, there it is! Everything matches.. IF the hardware clock is set to universal time. Knowing to do that comes from an uncountable number of debootstrap'ed Debian releases. The step can be found here under the "D.3.4.3. Setting Timezone" heading: https://www.debian.org/releases/wheezy/amd64/apds03.html.en#idp7856176 If your hardware clock is not UTC, I've never gone there so I don't know. My CHOICE is UTC because a tip many years ago advised that doing so helps our computers stay in sync more seamlessly with the rest of the World. Whether that's true or not, I don't know that, either, but going this route sure has taken the pain out of the local time keeping end of all of this *for me*. :) Cindy :) Notable: If /etc/adjtime exists and has data that is anything other than the 0.0s in there, my experience has been that occurs when I don't have my hardware clock set up properly. When I go the UTC/0.0 route, my file never changes. That data, those numbers, is/are the computer doing its own thing trying to keep things aligned based on .e.g our correct and incorrect date commands issued via programs like hwclock. -- Talking Rock, Pickens County, Georgia, USA * runs with birdseed *