检查给予的strftime格式相匹配的日期 [英] Check if given strftime format matches a date

查看:175
本文介绍了检查给予的strftime格式相匹配的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有时间的strftime格式,比方说(%Y-%M-%D%H:%M:%S)和文件应包含这样的数据如的(2012-02-11十七时15分00秒)。我需要检查,如果给定的模式数据实际相符。
如何处理呢? AWK,日期?

I have strftime format of time, let's say (%Y-%m-%d %H:%M:%S) and a file which should contain this kind of data e.g. (2012-02-11 17:15:00). I need to check if given pattern actually matches the data. How to approach this? awk, date?

编辑:
更多信息:用户输入的strftime格式,让我们输入说。然后,他进入它应该包含这些日期的文件。我需要确保,这些数据是有效的(他没有犯错误)。所以,我需要检查的行中输入文件看看,是否有给定的模式匹配的数据。例如:

More info: The user enters the strftime format, let's say on input. Then he enters a file which should contain those dates. I need to make sure, that those data are valid (he didn't make a mistake). So I need to check the rows in the input file and see, if there are data that matches the given pattern. Example:


  • 用户输入的strftime格式为:(%Y-%M-%D%H:%M:%S)

输入文件:(2012-02-11 17点15分〇〇秒)长句

有效的

VALID

用户输入的strftime格式为:日期[%Y.%M%D%H:%M:%S]

user enters strftime format: Date[%Y.%m.%d %H:%M:%S]

输入文件:日期-20​​12.02.11 17:15:00-长句

无效

INVALID

推荐答案

如果您允许使用外部辅助二进制,我写的 dateutils 来批量处理日期和时间数据。

If you allow an external helper binary, I've written dateutils to batch process date and time data.

dconv -q -i '(%Y-%m-%d %H:%M:%S)' <<EOF
not a match: 2012-04-10 12:00:00
a match: (2012-04-10 13:00:00)
EOF

会给

2012-04-10T13:00:00

-i 是输入格式, -q 燮presses警告。和 dconv 试图输入线转换为输出线(在此情况下它转换匹配行ISO标准格式。

-i is the input format, -q suppresses warnings. And dconv tries to convert input lines to output lines (in this case it converts matching lines to ISO standard format.

因此​​,使用此,一个文件相匹配完全如果输入行的数量等于输出线的数目。

So using this, a file matches completely if the number of input lines equals the number of output lines.

这篇关于检查给予的strftime格式相匹配的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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