date查看修改时间 ntpdate同步时间 chronyd同步时间 sleep休眠命令

2015-05-21 22:38:00
admin
原创 2939
摘要:date查看修改时间 ntpdate同步时间 chronyd同步时间 sleep休眠命令

一、linux时间相关命令使用

查看时间:

1、当前时区查看时间:date,Thu Dec  4 00:59:54 CST 2025

2、查看UTC时区时间:date -u,Wed Dec  3 16:59:57 UTC 2025

3、指定格式查看:date "+%Y-%m-%d %H:%M:%S",2015-05-21 23:00:56

4、查看时间戳:date "+%s",1764781302


查看指定时间:

1、当前时间:date -d now

2、昨天时间:date -d yesterday

3、两天以前:date -d "2 days ago"

4、50天以前:date -d "-50 days"
5、50天以后:date -d "50 days"

6、时间戳转换为时间:date -d @1447940395

7、时间戳转换为时间:date -d @1447940395.123


设置时间:

1、设置日期和时间:date -s "2025-03-09 14:30:30"

2、设置日期:date -s "2025-03-09",时间设置为00:00:00

3、设置时间:date -s "14:30:30"

4、查看CMOS硬件时钟:clock -r

5、设置CMOS硬件时钟:clock -w,修改系统时间后需要执行此操作


同步时间:

1、centos7手动同步:ntpdate time.nist.gov

2、centos8开始自动同步:systemctl start chronyd
3、centos8停止自动同步:systemctl stop chronyd

4、centos8自动同步状态:systemctl status chronyd

5、centos8自动同步状态:watch chronyc tracking,Not synchronised=同步失败

6、centos8自动同步时间源:chronyc sources -v
7、centos8手动同步:chronyd -q 'server time.nist.gov iburst'


详细说明:

       FORMAT controls the output.  Interpreted sequences are:

       %%     a literal %
       %a     locale’s abbreviated weekday name (e.g., Sun)
       %A     locale’s full weekday name (e.g., Sunday)
       %b     locale’s abbreviated month name (e.g., Jan)
       %B     locale’s full month name (e.g., January)
       %c     locale’s date and time (e.g., Thu Mar  3 23:05:25 2005)
       %C     century; like %Y, except omit last two digits (e.g., 20)
       %d     day of month (e.g, 01)
       %D     date; same as %m/%d/%y
       %e     day of month, space padded; same as %_d
       %F     full date; same as %Y-%m-%d
       %g     last two digits of year of ISO week number (see %G)
       %G     year of ISO week number (see %V); normally useful only with %V
       %h     same as %b
       %H     hour (00..23)
       %I     hour (01..12)
       %j     day of year (001..366)
       %k     hour ( 0..23)
       %l     hour ( 1..12)
       %m     month (01..12)
       %M     minute (00..59)
       %n     a newline
       %N     nanoseconds (000000000..999999999)
       %p     locale’s equivalent of either AM or PM; blank if not known
       %P     like %p, but lower case
       %r     locale’s 12-hour clock time (e.g., 11:11:04 PM)
       %R     24-hour hour and minute; same as %H:%M
       %s     seconds since 1970-01-01 00:00:00 UTC
       %S     second (00..60)
       %t     a tab
       %T     time; same as %H:%M:%S
       %u     day of week (1..7); 1 is Monday
       %U     week number of year, with Sunday as first day of week (00..53)
       %V     ISO week number, with Monday as first day of week (01..53)
       %w     day of week (0..6); 0 is Sunday
       %W     week number of year, with Monday as first day of week (00..53)
       %x     locale’s date representation (e.g., 12/31/99)
       %X     locale’s time representation (e.g., 23:13:48)
       %y     last two digits of year (00..99)
       %Y     year
       %z     +hhmm numeric timezone (e.g., -0400)
       %:z    +hh:mm numeric timezone (e.g., -04:00)
       %::z   +hh:mm:ss numeric time zone (e.g., -04:00:00)
       %:::z  numeric time zone with : to necessary precision (e.g., -04, +05:30)
       %Z     alphabetic time zone abbreviation (e.g., EDT)

       By default, date pads numeric fields with zeroes.  The following optional flags may follow ‘%’:
       -      (hyphen) do not pad the field
       _      (underscore) pad with spaces
       0      (zero) pad with zeros
       ^      use upper case if possible

       #      use opposite case if possible


二、sleep休眠命令

sleep 0.5,休眠0.5秒

sleep 10s,休眠10秒

sleep 1m, 休眠1分钟

usleep,默认休眠1微秒

usleep 100,休眠100微秒

发表评论
评论通过审核之后才会显示。