413
京東網上商城
linux顯示設置係統時間命令date詳解
顯示設置係統時間命令date,在寫shell腳本時經常會用到,date命令參數比較多,記住幾個常用的即可!
date命令選項
-d 字符串:顯示字符串所指的日期與時間,字符串前後必須加上雙引號
-s 字符串:根據字符串來設置日期與時間,字符串前後必須加上雙引號
-u:顯示或設置通用時間時間域,UTC,CST,GMT
--help:幫助
--version:版本信息
date命令參數
%% 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) 顯示年月日時間(例Mon 21 Nov 2016 11:15:40 AM CST )
%C century; like %Y, except omit last two digits (e.g., 20) 世紀
%d day of month (e.g, 01) 日期(01-31)
%D date; same as %m/%d/%y 年月日
%e day of month, space padded; same as %_d 日期(1-31)
%F full date; same as %Y-%m-%d 日期(和%Y-%m-%d一樣)
%g last two digits of year of ISO week number (see %G) 隻顯示年的後兩位16
%G year of ISO week number (see %V); normally useful only with %V 完整年份2016
%h same as %b 和%b一樣
%H hour (00..23) 24小時製(00-23)
%I hour (01..12) 12小時製(01-12)
%j day of year (001..366) 一年第幾天(001-366)
%k hour ( 0..23) 24小時製(0-23)
%l hour ( 1..12) 12小時製(1-12)
%m month (01..12) 月份(01-12)
%M minute (00..59) 分鍾(00-59)
%n a newline 換行
%N nanoseconds (000000000..999999999) 納秒(不明白的可以去搜納秒)
%p locale's equivalent of either AM or PM; blank if not known AM或PM
%P like %p, but lower case am或pm
%r locale's 12-hour clock time (e.g., 11:11:04 PM) 顯示時間12小時製
%R 24-hour hour and minute; same as %H:%M 顯示時間24小時製
%s seconds since 1970-01-01 00:00:00 UTC 從1970年1月1日00:00:00到目前所經曆的秒數
%S second (00..60) 秒(00-60)
%t a tab 製表符
%T time; same as %H:%M:%S 24小時製時間
%u day of week (1..7); 1 is Monday 一周的第幾天,1就是星期一
%U week number of year, with Sunday as first day of week (00..53) 一年的第幾周,周日為每周的第一天(00-53)
%V ISO week number, with Monday as first day of week (01..53) 一年的第幾周,周一為每周的第一天(01-53)
%w day of week (0..6); 0 is Sunday 一周的第幾天(0-6),0表示周日
%W week number of year, with Monday as first day of week (00..53) 一年的第幾周,周一為每周的第一天(00-53)
%x locale's date representation (e.g., 12/31/99) 日期(mm/dd/yy)
%X locale's time representation (e.g., 23:13:48) 時間(%H:%M:%S)
%y last two digits of year (00..99) 年份(00-99)和%g一樣
%Y year 見%G
%Z alphabetic time zone abbreviation (e.g., EDT) 時區
date幾個示例
設置時間
date -s 11:28:23 設置時間為11點28分23秒,原來的年月日不變
設置所有時間
date -s "11:28:23 2016-10-10" 這樣年月日也隨之改變
設置年月
date -s 20161010 這樣具體時間就變成了0點0分0秒
date -s "20120523 02:00:01"
七天前日期
date -d "7 day ago" +"%Y-%m-%d"
七天後日期
date -d "-7 day age" +"%Y-%m-%d"
上一月日期
date -d "-1 month" +"%Y-%m-%d"
下一月日期
date -d "1 month" +"%Y-%m-%d"
前一年日期
date -d "-1 year" +"%Y-%m-%d"
下一年日期
date -d "1 year" +"%Y-%m-%d"
最後更新:2017-06-28 09:32:10
上一篇:
用shell腳本打印九九乘法表
下一篇:
WordPress Gravatar國內加載緩慢解決辦法
《TensorFlow技術解析與實戰》——第2章 TensorFlow環境的準備 2.1下載TensorFlow 1.1.0
短視頻SDK基礎版、標準版、專業版的差異
顛覆大數據分析之Spark為Shark所提供的擴展
ubuntu下編寫開機自啟守護進程,並記錄進程信息到日誌文件
vxworks for x86讀取bios時間的解決方法
[數據庫]MySQL Hash索引和B-Tree索引的區別
Windows Phone 8讓諾基亞雪上加霜?
新型智慧城市:以信息為基礎的精確化管理
Spring-Bean的初始化(init方法和實現org.springframework.beans.factory.InitializingBean接口)
【玩轉數據係列十五】機器學習PAI為你自動寫歌詞,媽媽再也不用擔心我的freestyle了(提供數據、代碼)