Linux命令之日期時(shí)間命令date使用實(shí)例
date用法1:
格式:date [OPTION]... [+FORMAT]
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, space padded ( 0..23); same as %_H
%l hour, space padded ( 1..12); same as %_I
%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 time zone (e.g., -0400)
%:z +hh:mm numeric time zone (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
例如:
1.年月日
$ date +%Y%m%d
20150107
2.年月日,年只保留后兩位
~$ date +%y%m%d
150107
3.小時(shí)分鐘秒
~$ date +%H%M%S
233045
4.年月日時(shí)分秒
~$ date +%Y%m%d%H%M%S
20150107233145
相關(guān)文章

集成系統(tǒng)級Claw模式! Deepin 官宣發(fā)布 25.1 版本
deepin操作系統(tǒng)發(fā)布了最新的 25.1 版本更新,該版本基于 deepin 25 正式版積累的多輪內(nèi)測成果,在 AI 能力、內(nèi)核版本、桌面環(huán)境、文件管理器以及系統(tǒng)安全等方面進(jìn)行了更新2026-04-13
又一代老硬件退場! Linux 內(nèi)核正式放棄Intel 486 CPU
在過去的幾十年間,CPU 的架構(gòu)已經(jīng)經(jīng)歷了飛速發(fā)展,x86 系列就是其中之一,而 i486 則屬于該系列中的一個(gè),當(dāng)前,i486 的CPU處理器已經(jīng)夠老,從 Linux 7.1 開始將不再有對2026-04-09
趕緊收藏! 全網(wǎng)最全 Linux 命令總結(jié)
我把 Linux 中最常用、最實(shí)用、最常被問到的命令按照實(shí)際使用場景分類整理,方便你快速查閱和記憶,內(nèi)容覆蓋日常運(yùn)維、開發(fā)調(diào)試、性能分析、文件處理、網(wǎng)絡(luò)、安全、系統(tǒng)管2026-04-08
一分鐘內(nèi)檢查Linux服務(wù)器性能? 9個(gè)性能檢測常用的基本命令
今天我們來看看Linux系統(tǒng)中用于性能監(jiān)控的一系列命令,這些命令可以快速查看機(jī)器的負(fù)載情況,詳細(xì)請看下文介紹2026-03-18
從零基礎(chǔ)到精通! 適合高級用戶的15款Linux發(fā)行版推薦
Linux作為操作系統(tǒng)領(lǐng)域靈活性和可定制性的基石,提供了大量滿足不同用戶需求的發(fā)行版,今天分享適合高級用戶的15款Linux發(fā)行版2026-03-10
開箱即用? 這4個(gè)高手級Linux發(fā)行版遠(yuǎn)沒你想象的那么安全易用
如果你正在糾結(jié)用哪個(gè)發(fā)行版?零基礎(chǔ)新手別被“高端”“極客”“聲明式”這些詞沖昏頭腦,先用好用的,再慢慢進(jìn)階2026-03-10
這幾款SSH工具真的夠用了! Linux好用的ssh工具推薦
在Linux上使用SSH,您需要安裝一個(gè)SSH客戶端,今天整理找到的8 款 SSH / 終端工具,從免費(fèi)開源到企業(yè)級商用,從輕量化命令行到一站式工具箱,每款都做了介紹與對比,希望能2026-03-09
在Linux系統(tǒng)下有兩種用戶,即高級用戶root,普通用戶,高級用戶root可以在系統(tǒng)中做任何事情,普通用戶僅可在Linux系統(tǒng)中做有限的事情,下面我們就來看看切換方法2026-02-28
揭秘當(dāng)前登錄用戶的身份! Linux中使用logname命令的技巧
logname命令就是這樣一個(gè)簡單但強(qiáng)大的工具,它能幫助我們輕松獲取當(dāng)前登錄用戶的用戶名,今天,我們就來深入探索一下這個(gè)命令的工作原理、使用方法和最佳實(shí)踐2026-02-26
在 Linux 系統(tǒng)中,DNS 緩存是一種將域名和 IP 地址映射關(guān)系緩存在本地的機(jī)制,可以加快域名解析速度,并減輕 DNS 服務(wù)器的負(fù)載2026-02-26



