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

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

一、linux时间相关命令使用

查看时间:

当前时区查看时间:date //2015年 05月 21日 星期四 22:41:44 CST(China Standard Time)

查看UTC时区时间:date -u //2015年 05月 21日 星期四 14:42:44 UTC

指定格式查看:date "+%Y-%m-%d %H:%M:%S %x %X" //2015-05-21 23:00:56 2015年05月21日 23时00分56秒

查看时间戳:date "+%s" //1432310620 //seconds since 1970-01-01 00:00:00 UTC

当前时间:date -d now

昨天时间:date -d yesterday

2天以前:date -d "2 days ago"

100天以前的日期:date -d "-100 days"
50天后的日期:date -d "50 days"

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

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


设置时间:

设置日期:date -s "20150309",同时将时间设置为00:00:00

设置时间:date -s "14:31:00"

设置日期和时间:date -s "20150309 14:31:00"

查看CMOS硬件时钟:clock -r

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


同步时间:ntpdate time.nist.gov


详细说明:

       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微秒

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