Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am a new user and have Perl 4 installed on a DEC Unix system. I have to time stamp an entry for a report in one of two formats, either seconds from Epoch or in the format dd-MON-yyyy. I have tried the time function and get the number of seconds along with a space and the time(09:30:01). Is there a way to either return just seconds or if not return the other format (eg. 17-Jun-2002)? Thanks in advance.

Title edit by tye

Replies are listed 'Best First'.
Re: time
by mpeppler (Vicar) on Jun 17, 2002 at 18:41 UTC
    Both of the previous answers require perl 5 (and I encourage you to install perl 5, btw).

    But for a perl 4 answer you need to look at the time() function (which returns seconds since the epoch), and the localtime() function (which returns an array of items). Basic usage would look something like this:

    $secs = time(); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($secs); $year += 1900; @mname = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul' 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); printf("%2.2d-%3s-%4d", $mday, $mname[$mon], $year);

    Michael

      Perfect, Thanks Michael
Re: time
by stajich (Chaplain) on Jun 17, 2002 at 18:20 UTC
    use strict; use POSIX; print POSIX::strftime("%s %H:%M:%S",localtime(time)), "\n"; print POSIX::strftime("%d-%b-%Y",localtime(time)), "\n";
Re: time
by DamnDirtyApe (Curate) on Jun 17, 2002 at 18:22 UTC

    I don't have access to Perl 4 to test, but take a look at the time function, or the strftime function in the POSIX module.


    _______________
    D a m n D i r t y A p e
    Home Node | Email
      Sorry I'm so dumb, but I don't beleive I have POSIX on ths box. Can I add this module to Perl 4 and if so where can I get it?
        lib/POSIX.pm