【问题标题】:Alternative date command option in AIXAIX 中的替代日期命令选项
【发布时间】:2025-12-19 21:30:07
【问题描述】:

我想在 AIX 中将特定日期转换为时间戳。以下命令以 GNU/LINUX 风格运行。 有人可以帮我在 AIX 中完成它吗?

在 GNU/LINUX 上运行的命令:

命令 -> date -d"Nov 14 02:31" "+%s"

输出 -> 1542162660

【问题讨论】:

    标签: unix-timestamp aix


    【解决方案1】:

    如果你有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
    

    【讨论】: