我希望系统日期转换为ISO 8601格式.码:
my $now = time();
my $tz = strftime("%z", localtime($now));
$tz =~ s/(\d{2})(\d{2})/$1:$2/;
print "Time zone *******-> \"$tz\"\n";
# ISO8601
my $currentDate = strftime("%Y-%m-%dT%H:%M:%S", localtime($now)) . $tz;
print "Current date *******-> \"$currentDate\"\n";
Run Code Online (Sandbox Code Playgroud)
目前的输出是:
Time zone *******-> "-04:00"
Current date *******-> "2014-06-03T03:46:07-04:00"
Run Code Online (Sandbox Code Playgroud)
我希望当前日期的格式为"2014-07-02T10:48:07.124Z",这样我就可以计算出两者之间的差异.
我的文件内容如下:
Component (0463) "commonfiles"
Component (0464) "demo_new_comp"
Component (0467) "test_comp" (removed)
Component (0469) "test_comp3" (removed)
Component (0465) "textfiles1
Run Code Online (Sandbox Code Playgroud)
需要从具有(已删除)并放置在数组中的每一行的双引号内提取字符串.我的代码是:
my $fh = new IO::File;
$fh->open("<comp.log") or die "Cannot open comp.log";
my @comp_items;
while (<$fh>) {
if ( $_ =~ /removed/ ) {;
my $compName = $_ = ~ m/"(.*?)"/;
print " Componnet Name : \"$compName\"\n";
}
}
Run Code Online (Sandbox Code Playgroud)
我没有得到正确的输出给出一些数字:
"18446744073709551614"
"18446744073709551614"
Run Code Online (Sandbox Code Playgroud)
输出应该是:
test_comp
test_comp3
Run Code Online (Sandbox Code Playgroud) 我有脚本:
my $workItemCommentorURL = "https://almweb1.ipc.com/jts/users/sainis";
my $json_text= "curl -s -D - -k -b ~/.jazzcookies -o commentor.json -H \"Accept: application/x-oslc-cm*\" \"$workItemCommentorURL\"";
my $content = `cat commentor.json`;
my $WICommentCreator = `cat commentor.json | perl -l -ne '/<j.0:name>(.*)<\\/j.0:name>/ and print \$1'`;
print "NAME OF COMMENTOR ************-> \"$WICommentCreator\"\n";
Run Code Online (Sandbox Code Playgroud)
这给了我输出:
NAME OF COMMENTOR ************-> "Shalini Saini
"
Run Code Online (Sandbox Code Playgroud)
即Shalini Saini,接着是一条新线.代替
NAME OF COMMENTOR ************-> "Shalini Saini"
Run Code Online (Sandbox Code Playgroud)
为什么Saini之后会出现一条新线,为什么报价会出现在下一行?我怎么修剪它?
我有文件的内容为:
(0872) "ss_current" (1 of 1)
(0873) "ss_current_6oct" (0 of 1)
Run Code Online (Sandbox Code Playgroud)
我想读取每行文件,然后获取最后一个括号之间的内容,即
(1 of 1)
(0 of 1)
Run Code Online (Sandbox Code Playgroud)
并且如果它们相等则比较数字,即"of"之前和之后的数字相等.我的代码:
my @cs;
while (<$fh>) {
if ($_ =~ /\((.*?)\)/) {
my $temp = $1;
print $temp, "\n";
}
}
Run Code Online (Sandbox Code Playgroud)
但这给出的内容为0872
或0873
在将它们转换为纪元后,我计算了两个ISO 8601日期的差异.如何在天数中得出它们的差异?我的代码是
my $ResolvedDate = "2014-06-04T10:48:07.124Z";
my $currentDate = "2014-06-04T06:03:36-04:00"
my $resolved_epoch = &convert_time_epoch($ResolvedDate);
my $current_epoch = &convert_time_epoch($currentDate);
if (($resolvedDate - $currentDate) > $noOfDays) {
print "Difference in greater than x\n";
$built = 0;
return ($built);
} else {
print "Difference in smaller than x \n";
$built = 1;
return ($built);
}
sub convert_time_epoch {
my $time_c = str2time(@_);
my @time_l = localtime($time_c);
my $epoch = strftime("%s", @time_l);
return($epoch);
}
Run Code Online (Sandbox Code Playgroud)
这里除了$ built我还想要返回确切的天数,已解决的日期大于当前日期.