Last active
October 6, 2020 04:51
-
-
Save porteusconf/af95b8595c697a614169e3dfd9680010 to your computer and use it in GitHub Desktop.
howto manually set macos system date hwclock using file date or "YYYY-MM-DD hh:mm:ss" converted to required "+%m%d%H%M%Y"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### /usr/local/bin/datefix.sh | |
echo "DEMO: HowTo Change macos system date to date of /var/log/daily.out or manually" | |
echo "If dead bat or hwclock wrong, should work in single-user mode/recovery" | |
set -x | |
ls -l /var/log/daily.out | |
date -r /var/log/daily.out | |
date -r /var/log/daily.out "+%m%d%H%M%Y.%S" | |
date -ur /var/log/daily.out | |
date -ur /var/log/daily.out +"%Y-%m-%d %H:%M:%S" | |
date -ur /var/log/daily.out "+%m%d%H%M%Y.%S" | |
echo 'sudo date -u $(date -ur /var/log/daily.out "+%m%d%H%M%Y.%S") # or manually:' | |
## 2020-10-31 23:59:58 = 2 seconds before midnight on year 2020 month 10. and day 31 | |
echo 'sudo date -u $(date -ju -f "%Y-%m-%d %T" "2020-10-31 23:59:58" "+%m%d%H%M%Y") ' | |
## Once date is almost correct, and network is up, set time exactly from internet | |
echo 'sudo sntp -sS time.apple.com' # 10.13 and newer | |
echo 'sudo ntpdate -u time.apple.com' # 10.12 and earlier | |
echo 'date -u ; date # Should now be correct date in UTC, and in local time zone' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hopefully using -u to set date in UTC avoids dealing with timezone issues? In any case, be warned this is not thoroughly tested if at all, but did try to use output of date to debug date input conversions as shown at: https://stackoverflow.com/questions/38348963/how-to-convert-date-string-to-epoch-timestamp-with-the-os-x-bsd-date-command