当前位置: 首页 > news >正文

linux 计算字符串日期,在linux下获取时间字符串

命令 date

# 以yyyymmdd格式输出23天之前现在这个时刻的时间

$ date +%Y%m%d –date=’23 days ago’

$ date -u

Thu Sep 28 09:32:04 UTC 2006

$ date -R

Thu, 28 Sep 2006 17:32:28 +0800

# 测试十亿分之一秒

$ date +’%Y%m%d %H:%M:%S.%N’;date +’%Y%m%d %H:%M:%S.%N’;date +’%Y%m%d %H:%M:%S.%N’;date +’%Y%m%d %H:%M:%S.%N’

20060928 17:44:20.906805000

20060928 17:44:20.909188000

20060928 17:44:20.911535000

20060928 17:44:20.913886000

date 参考

$ date –help

Usage: date [OPTION]… [+FORMAT]

or: date [-u|–utc|–universal] [MMDDhhmm[[CC]YY][.ss]]

Display the current time in the given FORMAT, or set the system date.

-d, –date=STRING display time described by STRING, not `now’

# such as ‘n days ago |1 month ago|n years ago’

-f, –file=DATEFILE like –date once for each line of DATEFILE

-ITIMESPEC, –iso-8601[=TIMESPEC] output date/time in ISO 8601 format.

TIMESPEC=`date’ for date only,

`hours’, `minutes’, or `seconds’ for date and

time to the indicated precision.

–iso-8601 without TIMESPEC defaults to `date’.

-r, –reference=FILE display the last modification time of FILE

-R, –rfc-2822 output RFC-2822 compliant date string

-s, –set=STRING set time described by STRING

-u, –utc, –universal print or set Coordinated Universal Time

–help display this help and exit

–version output version information and exit

FORMAT controls the output. The only valid option for the second form

specifies Coordinated Universal Time. Interpreted sequences are:

%% 输出%符号 a literal %

%a 当前域的星期缩写 locale’s abbreviated weekday name (Sun..Sat)

%A 当前域的星期全写 locale’s full weekday name, variable length (Sunday..Saturday)

%b 当前域的月份缩写 locale’s abbreviated month name (Jan..Dec)

%B 当前域的月份全称 locale’s full month name, variable length (January..December)

%c 当前域的默认时间格式 locale’s date and time (Sat Nov 04 12:02:33 EST 1989)

%C n百年 century (year divided by 100 and truncated to an integer) [00-99]

%d 两位的天 day of month (01..31)

%D 短时间格式 date (mm/dd/yy)

%e 短格式天 day of month, blank padded ( 1..31)

%F 文件时间格式 same as %Y-%m-%d

%g the 2-digit year corresponding to the %V week number

%G the 4-digit year corresponding to the %V week number

%h same as %b

%H 24小时制的小时 hour (00..23)

%I 12小时制的小时 hour (01..12)

%j 一年中的第几天 day of year (001..366)

%k 短格式24小时制的小时 hour ( 0..23)

%l 短格式12小时制的小时 hour ( 1..12)

%m 双位月份 month (01..12)

%M 双位分钟 minute (00..59)

%n 换行 a newline

%N 十亿分之一秒 nanoseconds (000000000..999999999)

%p 大写的当前域的上下午指示 locale’s upper case AM or PM indicator (blank in many locales)

%P 小写的当前域的上下午指示 locale’s lower case am or pm indicator (blank in many locales)

%r 12小时制的时间表示(时:分:秒,双位) time, 12-hour (hh:mm:ss [AP]M)

%R 24小时制的时间表示 (时:分,双位)time, 24-hour (hh:mm)

%s 自基础时间 1970-01-01 00:00:00 到当前时刻的秒数 seconds since `00:00:00 1970-01-01 UTC’ (a GNU extension)

%S 双位秒 second (00..60); the 60 is necessary to accommodate a leap second

%t 横向制表位(tab) a horizontal tab

%T 24小时制时间表示 time, 24-hour (hh:mm:ss)

%u 数字表示的星期(从星期一开始 1-7)day of week (1..7); 1 represents Monday

%U 一年中的第几周星期天为开始 week number of year with Sunday as first day of week (00..53)

%V 一年中的第几周星期一为开始 week number of year with Monday as first day of week (01..53)

%w 一周中的第几天 星期天为开始 0-6 day of week (0..6); 0 represents Sunday

%W 一年中的第几周星期一为开始 week number of year with Monday as first day of week (00..53)

%x 本地日期格式 locale’s date representation (mm/dd/yy)

%X 本地时间格式 locale’s time representation (%H:%M:%S)

%y 两位的年 last two digits of year (00..99)

%Y 年 year (1970…)

%z RFC-2822 标准时间格式表示的域 RFC-2822 style numeric timezone (-0500) (a nonstandard extension)

%Z 时间域 time zone (e.g., EDT), or nothing if no time zone is determinable

By default, date pads numeric fields with zeroes. GNU date recognizes

the following modifiers between `%’ and a numeric directive.

`-’ (hyphen) do not pad the field

`_’ (underscore) pad the field with spaces

相关文章:

  • linux 阻止 复位命令,Linux下锁定账号,禁止登录系统的设置总结
  • Linux怎么看每一级别的权限,linux 特殊权限chattr(文件系统级别的权限) Attr 权限和 ACL访问控制列表 ......
  • 改文件命名linux,linux下修改文件名称
  • 小米网卡驱动linux,小米笔记本pro 15.6寸安装ubuntu16.04无法使用wifi的解决方法
  • fopen函数在linux,Fopen()是Linux中的一个线程安全函数吗?
  • linux vnc登录日志,CentOS安装使用VNC进行远程桌面登录
  • 鸟哥linux视频教程密码,[鸟哥linux视频教程整理]04_01_Linux用户管理命令详解
  • linux memcpy 地址对齐,在memcpy中对齐源地址和目标地址
  • 红帽企业级Linux.As版,晋级Linux中的默认JDK的版本
  • linux xen 参数配置,XEN linux虚拟机配置实例
  • linux cpu占用分析,Linux下CPU占用率高分析方法
  • linux信号处理响应异步事件,Linux并发(异步信号)
  • redis 3.0.0 linux下载,Redis可视化管理软件RedisPlus 3.0.0下载,优化了性能及交互体验...
  • c语言阶乘 ii多测试,C语言经典题目:求阶乘n!=n*(n-1)*...*1,阶乘和s=1!+(2)!+(3)!+...+n!...
  • 利用c语言实现几何图形旋转,[平顶山学院高等数学C语言试题.doc
  • [ 一起学React系列 -- 8 ] React中的文件上传
  • Angularjs之国际化
  • CentOS 7 防火墙操作
  • Docker下部署自己的LNMP工作环境
  • Eureka 2.0 开源流产,真的对你影响很大吗?
  • idea + plantuml 画流程图
  • js中的正则表达式入门
  • KMP算法及优化
  • LeetCode算法系列_0891_子序列宽度之和
  • node学习系列之简单文件上传
  • Python3爬取英雄联盟英雄皮肤大图
  • sessionStorage和localStorage
  • SQLServer之索引简介
  • Tornado学习笔记(1)
  • 你真的知道 == 和 equals 的区别吗?
  • 如何正确配置 Ubuntu 14.04 服务器?
  • 基于django的视频点播网站开发-step3-注册登录功能 ...
  • #【QT 5 调试软件后,发布相关:软件生成exe文件 + 文件打包】
  • #14vue3生成表单并跳转到外部地址的方式
  • #使用清华镜像源 安装/更新 指定版本tensorflow
  • ${factoryList }后面有空格不影响
  • $refs 、$nextTic、动态组件、name的使用
  • (AngularJS)Angular 控制器之间通信初探
  • (Redis使用系列) Springboot 在redis中使用BloomFilter布隆过滤器机制 六
  • (八)五种元启发算法(DBO、LO、SWO、COA、LSO、KOA、GRO)求解无人机路径规划MATLAB
  • (差分)胡桃爱原石
  • (附源码)spring boot校园拼车微信小程序 毕业设计 091617
  • (七)Knockout 创建自定义绑定
  • (一)ClickHouse 中的 `MaterializedMySQL` 数据库引擎的使用方法、设置、特性和限制。
  • (转)chrome浏览器收藏夹(书签)的导出与导入
  • (转)详解PHP处理密码的几种方式
  • (转载)Linux网络编程入门
  • .\OBJ\test1.axf: Error: L6230W: Ignoring --entry command. Cannot find argumen 'Reset_Handler'
  • .htaccess配置重写url引擎
  • .mat 文件的加载与创建 矩阵变图像? ∈ Matlab 使用笔记
  • .naturalWidth 和naturalHeight属性,
  • .NET Core MongoDB数据仓储和工作单元模式封装
  • .net core Swagger 过滤部分Api
  • .NET/C# 使用 SpanT 为字符串处理提升性能
  • .net和jar包windows服务部署