GNU日期和自定义格式 [英] GNU date and custom formats

查看:112
本文介绍了GNU日期和自定义格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些使用特定日期格式的字符串,我想使用GNU date命令(coreutils 8.20)进行处理.我可以使用+ FORMAT字符串获取要输出的日期,但不能理解使用相同字符串输入至其中的字符串.我很确定我缺少明显的东西.有什么作用?

I have some strings in a specific date format that I'd like to work on using the GNU date command (coreutils 8.20). I can get date to output using the +FORMAT string, but not to understand strings input into it using the same string. I'm quite sure I'm missing something obvious. What gives?

teggl@mckinley { ~/scripts }$ date +%Y%m%dT%H%M%S
20131202T182052
teggl@mckinley { ~/scripts }$ date --date="20131202T182052" +%Y%m%dT%H%M%S
date: invalid date ‘20131202T182052’

注意:我不是要进行awk-y字符串解析,我需要日期来了解输入的日期,因此它知道它是否有效(例如,日期20140231T120000将是不可能的).

Note: I'm not looking for awk-y string parsing, I need date to understand the date input into it, so it knows if it's valid (e.g. the date 20140231T120000 would be impossible).

推荐答案

每个手册页:

-date = STRING是一种大多数人可读的自由格式日期 字符串,例如"Sun,2004年2月29日16:21:42 -0800"或"2004-02-29 16:21:42",甚至下一个星期四".日期字符串可能包含项目 指示日历日期,一天中的时间,时区,星期几, 相对时间,相对日期和数字.空字符串表示 一天的开始.日期字符串格式比 很容易在这里记录下来,但在信息中有完整描述 文档.

The --date=STRING is a mostly free format human readable date string such as "Sun, 29 Feb 2004 16:21:42 -0800" or "2004-02-29 16:21:42" or even "next Thursday". A date string may contain items indicating calendar date, time of day, time zone, day of week, relative time, relative date, and numbers. An empty string indicates the beginning of the day. The date string format is more complex than is easily documented here but is fully described in the info documentation.

"T"似乎使它感到困惑.这有效:

The "T" seems to confuse it. This works:

$ date --date="2013-12-02 18:20:52" +%Y%m%dT%H%M%S
20131202T182052

输出格式与输入格式无关.

The output format has nothing to do with the input format.

这篇关于GNU日期和自定义格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆