【发布时间】:2020-11-27 15:26:32
【问题描述】:
如果我们去SystemPreferences > date and time,我们可以更改我们mac的日期。你能创建一个终端可执行程序来更改我打开它的日期吗?
【问题讨论】:
如果我们去SystemPreferences > date and time,我们可以更改我们mac的日期。你能创建一个终端可执行程序来更改我打开它的日期吗?
【问题讨论】:
您可以在终端使用以下命令更改 mac 的日期。
date -u {month}{day}{hour}{minute}{year}
用两位数替换括号。要设置,2020 年 10 月 16 日 21:16 将变为以下命令:
date 1016211620
或者你可以创建苹果脚本来做到这一点:
set ntpdPID to do shell script "systemsetup -getusingnetworktime; exit 0" with administrator privileges
if ntpdPID is "Network Time: On" then
do shell script "systemsetup -setusingnetworktime off" with administrator privileges
do shell script "systemsetup -setdate '01:24:1984' -settime '03:00:00'" with administrator privileges
else
do shell script "systemsetup -setusingnetworktime on" with administrator privileges
end if
要创建苹果脚本,请参阅reference
【讨论】:
sudo sntp -sS time.apple.com 会将日期和时间设置为当前日期和时间。