AIX 中的备用日期命令选项
Alternative date command option in AIX
我想在 AIX 中将特定日期转换为时间戳。以下命令适用于 GNU/LINUX 风格。
有人可以帮我在 AIX 中完成它吗?
GNU/LINUX 上的命令:
命令 -> date -d"Nov 14 02:31" "+%s"
输出 -> 1542162660
如果你有 POSIX::strptime
,你可以用 Perl 做这样的事情
示例程序(totimestamp.pl):
#!/usr/bin/perl
use strict;
use POSIX ("tzset", "mktime");
use POSIX::strptime;
POSIX::tzset ();
my $ARGC= scalar (@ARGV);
my $tstamp;
if ($ARGC < 1) {
$tstamp= time ();
} else {
my $tstr= $ARGV[0];
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst);
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
POSIX::strptime($tstr, "%b %d %H:%M:%S %Y");
$tstamp= POSIX::mktime ($sec, $min, $hour, $mday, $mon, $year);
}
printf ("%d\n", $tstamp);
用法:
perl ./totimestamp.pl "Nov 16 14:40:00 2018"
1542375600
我想在 AIX 中将特定日期转换为时间戳。以下命令适用于 GNU/LINUX 风格。 有人可以帮我在 AIX 中完成它吗?
GNU/LINUX 上的命令:
命令 -> date -d"Nov 14 02:31" "+%s"
输出 -> 1542162660
如果你有 POSIX::strptime
,你可以用 Perl 做这样的事情
示例程序(totimestamp.pl):
#!/usr/bin/perl
use strict;
use POSIX ("tzset", "mktime");
use POSIX::strptime;
POSIX::tzset ();
my $ARGC= scalar (@ARGV);
my $tstamp;
if ($ARGC < 1) {
$tstamp= time ();
} else {
my $tstr= $ARGV[0];
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst);
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
POSIX::strptime($tstr, "%b %d %H:%M:%S %Y");
$tstamp= POSIX::mktime ($sec, $min, $hour, $mday, $mon, $year);
}
printf ("%d\n", $tstamp);
用法:
perl ./totimestamp.pl "Nov 16 14:40:00 2018"
1542375600