linux date -d参数用法
最近偶为了写一个调整时间的shell而绞尽脑汁,结果在某一天
#info data
这里面看到了data -d参数的灵活用法,真是欣喜若狂。好东西要保存,整理整理:
* To print the date of the day before yesterday:
date --date='2 days ago'
* To print the date of the day three months and one day hence:
date --date='3 months 1 day'
* To print the day of year of Christmas in the current year:
date --date='25 Dec' +%j
* To print the current full month name and the day of the month:
date '+%B %d'
But this may not be what you want because for the first nine days
of the month, the `%d' expands to a zero-padded two-digit field,
for example `date -d 1may '+%B %d'' will print `May 01'.
* To print a date without the leading zero for one-digit days of the
month, you can use the (GNU extension) `-' flag to suppress the
padding altogether:
date -d 1may '+%B %-d
* To print the current date and time in the format required by many
non-GNU versions of `date' when setting the system clock:
date +%m%d%H%M%Y.%S
* To set the system clock forward by two minutes:
date --set='+2 minutes'
* To print the date in RFC 2822 format, use `date --rfc-2822'. Here
is some example output:
Fri, 09 Sep 2005 13:51:39 -0700
* To convert a date string to the number of seconds since the epoch
(which is 1970-01-01 00:00:00 UTC), use the `--date' option with
the `%s' format. That can be useful in sorting and/or graphing
and/or comparing data by date. The following command outputs the
number of the seconds since the epoch for the time two minutes
after the epoch:
date --date='1970-01-01 00:02:00 +0000' +%s
date --date='1970-01-01 00:02:00 +0000' +%s
120
If you do not specify time zone information in the date string,
`date' uses your computer's idea of the time zone when
interpreting the string. For example, if your computer's time
zone is that of Cambridge, Massachusetts, which was then 5 hours
(i.e., 18,000 seconds) behind UTC:
# local time zone used
date --date='1970-01-01 00:02:00' +%s
18120
* If you're sorting or graphing dated data, your raw date values may
be represented as seconds since the epoch. But few people can
look at the date `946684800' and casually note "Oh, that's the
first second of the year 2000 in Greenwich, England."
date --date='2000-01-01 UTC' +%s
946684800
An alternative is to use the `--utc' (`-u') option. Then you may
omit `UTC' from the date string. Although this produces the same
result for `%s' and many other format sequences, with a time zone
offset different from zero, it would give a different result for
zone-dependent formats like `%z'.
date -u --date=2000-01-01 +%s
946684800
To convert such an unwieldy number of seconds back to a more
readable form, use a command like this:
# local time zone used
date -d '1970-01-01 UTC 946684800 seconds' +"%Y-%m-%d %T %z"
1999-12-31 19:00:00 -0500
Often it is better to output UTC-relative date and time:
date -u -d '1970-01-01 946684800 seconds' +"%Y-%m-%d %T %z"
2000-01-01 00:00:00 +0000
linux date -d参数用法的更多相关文章
- [转帖]Linux date命令的用法(转)
Linux date命令的用法(转) https://www.cnblogs.com/asxe/p/9317811.html 1.命令:date 2.命令功能:date 可以用来显示或设定系统的日期与 ...
- Linux date命令的用法(转)
1.命令:date 2.命令功能:date 可以用来显示或设定系统的日期与时间. 3.命令参数 -d<字符串>:显示字符串所指的日期与时间.字符串前后必须加上双引号: -s<字符串& ...
- Linux date命令的用法
在linux shell编程中,经常用到日期的加减运算以前都是自己通过expr函数计算,很麻烦.其实date命令本身提供了日期的加减运算非常方便. 例如:得到昨天的时间date --date=&qu ...
- 11.Linux date命令的用法
date命令常的日常应用 修改时间 date -s “2008/05/23 19:20″ 打包文件 tar zcvf log-$(date +$F).gz /home/admin/logs 同步阿 ...
- linux mount命令参数及用法详解
linux mount命令参数及用法详解 非原创,主要来自 http://www.360doc.com/content/13/0608/14/12600778_291501907.shtml. htt ...
- 【转】linux expr命令参数及用法详解
在抓包过程中,查看某个设定时间内,数据上下行多少,用命令expr 计算! --------------------------------------------------------------- ...
- linux dmesg命令参数及用法详解(linux显示开机信息命令)
linux dmesg命令参数及用法详解(linux显示开机信息命令) http://blog.csdn.net/zhongyhc/article/details/8909905 功能说明:显示开机信 ...
- linux sed命令参数及用法详解
linux sed命令参数及用法详解 http://blog.csdn.net/namecyf/article/details/7336308 1. Sed简介 sed 是一种在线编辑器,它一次处理一 ...
- linux scp命令参数及用法详解--linux远程复制拷贝命令使用实例【转】
转自:http://blog.csdn.net/jiangkai_nju/article/details/7338177 一般情况,本地网络跟远程网络进行数据交抱,或者数据迁移,常用的有三种方法,一是 ...
随机推荐
- Linux内核参数优化记录
//fs.file-max 最大打开文件数 //fs.nr_open=20480000 单个进程允许打开的文件句柄上限 //信号量及共享内存,可以使用ipcs -l来获取 //kernel.sem 信 ...
- pip删除依赖、配置虚拟环境
问题:跑openpose代码的时候,出现问题 tensorpack 0.8.6 requires tqdm>4.11.1, which is not installed.tf-pose 0.1. ...
- layer弹出相册层
如果想要制作一个简单的相册,可以采用这个插件的方法.如果你的图片是从后台传过来的json格式里,可以通过ajax加载让图片显示在页面上,然后在使用layer插件,做出点击以后就可以查看大图的效果. 一 ...
- https页面证书验证、加密过程简介
1.服务器向CA机构获取证书(假设这个证书伪造不了),当浏览器首次请求服务器的时候,服务器返回证书给浏览器.(证书包含:公钥+申请者与颁发者的相关信息+签名) 2.浏览器得到证书后,开始验证证书的相关 ...
- Linux下XordDos木马的清除
朋友的阿里云服务器一早上报木马入侵,找我处理,登陆阿里云查看警告信息“恶意进程(云查杀)-XorDDoS木马”, 本文也可以作为服务器处理木马排查的步骤的参考文章 排查原则: 1.一般的木马都有多个守 ...
- linux shell except tcl login ssh Automatic interaction
/*************************************************************************************** * linux she ...
- 【转载】Python字符串操作之字符串分割与组合
1. str.split():字符串分割函数 通过指定分隔符对字符串进行切片,并返回分割后的字符串列表. 语法: str.split(s, num)[n] 参数说明: s:表示指定的分隔符,不写的话, ...
- (3)re模块(正则表达式模块)
什么是正则表达式 正则就是用一些具有特殊含义的符号组合到一起(称为正则表达式)来描述字符或者字符串的方法.或者说:正则就是用来描述一类事物的规则.(在Python中)它内嵌在Python中,并通过 r ...
- Windows环境下搭建Nginx和多版本PHP共存
PHP版本众多,彼此之间兼容性不好,不同程序经常需要的不同版本的PHP版本.这里介绍如何使用NGINX让不同版本的PHP共存. 软件下载地址 与nginx整合的php需要选择Non Thread Sa ...
- 强大的Java Json工具类
转自: https://blog.csdn.net/u014676619/article/details/49624165 import java.io.BufferedReader; import ...