Linux命令之日期时间命令date使用实例
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.小时分钟秒
~$ date +%H%M%S
233045
4.年月日时分秒
~$ date +%Y%m%d%H%M%S
20150107233145
相关文章

Fedora Linux 42 稳定版发布: 带来大量新功能和软件更新
Fedora 42昨日发布,这是 Red Hat 赞助开发的杰出前沿 Linux 发行版的最新版,包含大量新功能和软件更新,使其成为 2025 年上半年发布的一款出色的 Linux 操作系统之一,内2025-04-16
如何在Linux查看硬盘信息? 查看Linux硬盘大小类型和硬件信息的5种方法
使用Linux系统的过程中,查看和了解硬盘信息是非常重要的工作,尤其是对于系统管理员而言,那么在Linux系统中如何查看硬盘信息?以下是具体内容介绍2025-03-12
如何在 Linux 中查看 CPU 详细信息? 3招轻松查看CPU型号、核心数和温度
在日常运维工作中,获取 CPU 信息是系统运维管理员常见的工作内容,无论是为了性能调优、硬件升级还是仅仅满足好奇心2025-03-11
什么是 Arch Linux? 独树一帜的Arch Linux发行版分析
Arch Linux是为简化,优化,现代化,实用主义,用户中心和多功能性而创建Linux发行版,究竟是什么让 Arch 与众不同?下面我们就来简要解读2025-02-19
一直用的linux办公,想要将笔记本电脑从 Linux 系统切换回 Windows 11,我们可以制作一个win11装机u盘,详细如下2025-02-17
Rsnapshot怎么用? 基于Rsync的强大Linux备份工具使用指南
Rsnapshot 不仅可以备份本地文件,还能通过 SSH 备份远程文件,接下来详细介绍如何安装、配置和使用 Rsnapshot,包括创建每小时、每天、每周和每月的本地备份,以及如何进2025-02-06
Linux Kernel 6.13发布:附更新内容及新特性解读
Linux 内核 6.13 正式发布,新版本引入了惰性抢占支持,简化内核抢占逻辑,通过减少与调度器相关的调用次数,让内核在运行时表现更优,从而提高效率2025-01-23
五大特性引领创新! 深度操作系统 deepin 25 Preview预览版发布
今日,深度操作系统正式推出deepin 25 Preview版本,该版本集成了五大核心特性:磐石系统、全新DDE、Treeland窗口合成器、AI For OS以及Distrobox子系统2025-01-18
Linux Mint Xia 22.1重磅发布: 重要更新一览
Beta 版 Linux Mint“Xia” 22.1 发布,新版本基于 Ubuntu 24.04,内核版本为 Linux 6.8,这次更新带来了诸多优化和改进,进一步巩固了 Mint 在 Linux 桌面操作系统领域的2025-01-16
LinuxMint怎么安装? Linux Mint22下载安装图文教程
Linux Mint22发布以后,有很多新功能,很多朋友想要下载并安装,该怎么操作呢?下面我们就来看看详细安装指南2025-01-16









最新评论