1 2 3 4 5 6 7 8 9 10
#!/usr/bin/perl use POSIX; use strict; use warnings; my $file=shift(@ARGV) // '/etc/fstab'; my $timestr=POSIX::strftime( "%Y-%m-%d_%H:%M:%S", localtime(( stat $file )[9] ) ); print "$timestr\n";
1 2 3 4 5 6 7 8 9 10 11 12
#!/usr/bin/perl use strict; use warnings; my $file=shift(@ARGV) // '/etc/fstab'; my @date=reverse((localtime(( stat $file )[9] ))[0..5]); $date[0]+=1900; $date[1]+=1; my $timestr=sprintf('%04u-%02u-%02u_%02u:%02u:%02u',@date); print "$timestr\n";
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/perl -w
use strict;
use warnings;
use DateTime;
my @filestats = stat '/etc/fstab';
my $atime = $filestats[8];
my $mtime = $filestats[9];
my $ctime = $filestats[10];
print "atime als epochtime = $atime atime im gewuenschten format new = ",convert_epochtime($atime),"\n";
print "mtime als epochtime = $mtime atime im gewuenschten format new = ",convert_epochtime($mtime),"\n";
print "ctime als epochtime = $ctime atime im gewuenschten format new = ",convert_epochtime($ctime),"\n";
sub convert_epochtime {
my $epochtime = shift;
my $dt = DateTime->from_epoch( epoch => $epochtime );
my $newtimeformat = $dt->ymd;
$newtimeformat .= '_';
$newtimeformat .= $dt->hms;
return ($newtimeformat);
}
1;