我需要在日志文件中搜索时间范围。时间戳记采用JDE朱利安日期格式,因此我无法使用模块。
日期格式为YYYYJJJHHMMSS
地方JJJ
是在朱利安的日子。
我需要在不使用模块的情况下转换JDE中的用户输入。
这些数字是日期/时间值的事实没有区别。它们是整数(尽管相当大),并且可以与任何其他整数完全相同的方式进行比较。
while (<$your_input_filehandle>) {
# I have no idea of the format of your input data, so I can't
# begin to implement extract_timestamp()
my $this_records_timestamp = extract_timestamp($_);
if ($this_records_timestamp >= $min_timestamp and
$this_records_timestamp <= $max_timestamp) {
# timestamp is within the given range
}
}
更新:将YYYYMMDD转换为YYYYJJ
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
use Time::Piece;
my $in_format = '%Y%m%d';
my $out_format = '%Y%j';
my $in_date = shift
|| die "Please pass date in format YYYYMMDD\n";
my $date = Time::Piece->strptime($in_date, $in_format);
say $date->strftime($out_format);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句