I'm sure someone will have an easier way, but this does it:
(The $time variable will have the format you want.)
#!perl
$ourtime=localtime();
$ourtime=~s/ +/ /g;
($day_word,$month,$day_num,$time,$year)=split(/ /, $ourtime);
print TIME: $time\n;
Scott Campbell
Senior Software Developer
Somix
Michael,
Most likely you got a ton of emails on this one - here you go Ciao!
use Date::Manip;
my ($mydate) = (${\ParseDate(today)} =~ /(\d{2}:\d{2}:\d{2})$/);
print $mydate\n;
The routine ParseDate - takes today or a variable containing a date
and returns mmddhh:mm:ss
I use the
Basic code would be like this :
my
($nowsec,$nowmin,$nowhour,$nowmday,$nowmon,$nowyear,$nowwday,$nowyday,$nowis
dst) = localtime(time());
print $nowhour:$nowmin:$nowsec\n ;
But this raw code will display for instance
14:06:02
like this
14:6:2
so here is some code that will correctly
PROTECTED]]
Sent: Friday, August 09, 2002 8:41 AM
To: [EMAIL PROTECTED];
[EMAIL PROTECTED]
Cc: 'Michael C. Podlesny'
Subject: RE: Displaying time in PERL
Basic code would be like this :
my
($nowsec,$nowmin,$nowhour,$nowmday,$nowmon,$nowyear,$nowwday,$nowyday,$nowis
dst) = localtime(time());
print
/Systems Administrator
-Original Message-
From: Hill, David K [SMTP:[EMAIL PROTECTED]]
Sent: Friday, August 09, 2002 5:49 PM
To: 'Bellenger, Bruno (Paris)';
[EMAIL PROTECTED];
[EMAIL PROTECTED]
Cc: 'Michael C. Podlesny'
Subject: RE: Displaying time in PERL
Or you could do
From: Charbeneau, Chuck [mailto:[EMAIL PROTECTED]]
Subject: RE: Displaying time in PERL
printf (%02d:%02d:%02d,(localtime(time))[2,1,0]);
Chuch Charbeneau
^
|
But how can you trust the code from a man who can't spell his own name?
Chuck Charbeneau
Michael C. Podlesny wrote:
can anyone tell me how to get the time in the format of hh:mm:ss?
1)
use POSIX qw(strftime);
my $time = strftime %H:%M:%S\n, localtime;
2)
my $time = sprintf %02u:%02u:%02u, (localtime)[2, 1, 0];
You can replace localtime with gmtime for UTC/GMT time.
--
,-/-
To: [EMAIL PROTECTED]
Subject: RE: Displaying time in PERL
printf (%02d:%02d:%02d,(localtime(time))[2,1,0]);
Chuch Charbeneau
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman
From: Bellenger, Bruno (Paris) [mailto:[EMAIL PROTECTED]]
Subject: RE: Displaying time in PERL
Shortest one so far. And not even bad on the obfuscation criteria.
Well done.
printf (%02d:%02d:%02d,(localtime(time))[2,1,0]);
I can't take credit for it, I saw someone else use a slice
, Chuck [mailto:[EMAIL PROTECTED]]
Sent: Friday, August 09, 2002 11:02 AM
To: 'Bellenger, Bruno (Paris)'; [EMAIL PROTECTED]
Subject: RE: Displaying time in PERL
From: Bellenger, Bruno (Paris) [mailto:[EMAIL PROTECTED]]
Subject: RE: Displaying time in PERL
Shortest one so far. And not even bad
10 matches
Mail list logo