crontab定时脚本执行时间与系统时间不一致

事情源于在树莓派上写的定时脚本,定时获取停车费用信息。ubuntu重装后时区都用tzselect设置了,但仍在半夜收到消息通知。
于是发现需要这样设置下。

执行这个设置成中国时区 timedatectl set-timezone Asia/Shanghai

查看本地时间 timedatectl status

还有最重要的,要重启下crontab的服务. systemctl restart cron
有些系统中crontab服务为 crond。

更多关于timedatectl的帮助可以查看这个:

timedatectl --help
timedatectl [OPTIONS...] COMMAND ...

Query or change system time and date settings.

Commands:
  status                   Show current time settings
  show                     Show properties of systemd-timedated
  set-time TIME            Set system time
  set-timezone ZONE        Set system time zone
  list-timezones           Show known time zones
  set-local-rtc BOOL       Control whether RTC is in local time
  set-ntp BOOL             Enable or disable network time synchronization

systemd-timesyncd Commands:
  timesync-status          Show status of systemd-timesyncd
  show-timesync            Show properties of systemd-timesyncd

Options:
  -h --help                Show this help message
     --version             Show package version
     --no-pager            Do not pipe output into a pager
     --no-ask-password     Do not prompt for password
  -H --host=[USER@]HOST    Operate on remote host
  -M --machine=CONTAINER   Operate on local container
     --adjust-system-clock Adjust system clock when changing local RTC mode
     --monitor             Monitor status of systemd-timesyncd
  -p --property=NAME       Show only properties by this name
  -a --all                 Show all properties, including empty ones
     --value               When showing properties, only print the value