Re: Localtime
by Coruscate (Sexton) on Feb 14, 2003 at 22:43 UTC
|
my ($month) = localtime =~ m#^[^ ]+ (\w{3})#;
print $month, "\n";
If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, reply to this node or /msg me to tell me what is wrong with the post, so that I may update the node to the best of my ability. If you do not inform me as to why the post deserved a downvote, your vote does not have any significance and will be disregarded.
| [reply] [Watch: Dir/Any] [d/l] |
|
my $month = lc((split ' ',localtime)[1]);
or
my @months = qw( jan feb mar apr may jun jul aug sep oct nov dec )
+;
my $month = $months[ (localtime)[4] ];
jdporter The 6th Rule of Perl Club is -- There is no Rule #6. | [reply] [Watch: Dir/Any] [d/l] [select] |
|
print scalar(localtime), "\n";
localtime returns a time string like:
Fri Feb 14 14:53:08 2003
I never actually realized it until you pointed it out. I always did it the hard way and constructed an array of month names.
Thanks coruscate++
Where do you want *them* to go today? | [reply] [Watch: Dir/Any] [d/l] [select] |
|
Awesome, thank you! One more question, please.
What I'm trying to do, is get the month, then I'm going to build a popup_menu using CGI.pm that has that months days in it as the values they can select.
However, know I realize that there must be a module that I might be able to find that already does that, otherwise I'd have to create 12 hashes, one for each month, then call that, depending on the value of the month.
Ex: jan has 31 days, so the days popup_menu would have 1 - 31 to be selected from. feb has 28, possibly 29... etc.
Is there a module that does that.
Sorry for the trouble. I should have realized that 15 mins ago, before I asked the other question.
Thank you for any module you can think of for me. I am not good with knowing what modules are and so forth.
thx,
Richard
| [reply] [Watch: Dir/Any] |
|
The module Calendar::Simple will do it.
Here is how you could use it to get the days in the current month (it gets the last day of the last week of the month):
use strict;
use Calendar::Simple;
my $mon = (localtime)[4] + 1;
my $yr = ((localtime)[5] + 1900);
my @month = calendar($mon, $yr);
print $month[-1][-1],"\n";
| [reply] [Watch: Dir/Any] [d/l] |
|
Re: Localtime
by Abigail-II (Bishop) on Feb 15, 2003 at 01:11 UTC
|
I would use strftime from the POSIX module.
That gives you the ability to format your date/time in
lots and lots of ways.
$ perl -MPOSIX -wle 'print strftime "%b" => localtime'
Feb
Abigail
| [reply] [Watch: Dir/Any] [d/l] [select] |
Re: Localtime
by steves (Curate) on Feb 15, 2003 at 11:14 UTC
|
I didn't realize until investigating this thread that the scalar return of localtime is a built-in and is not locale dependent. I figured it was like UNIX ctime so I cringed at some of the scalar solutions since I thought they'd break if the default time locale setting changed. But I was wrong.
Before realizing this, my first choice would have been to use the POSIX strftime method as proposed by Abigail-II. Another way is this:
$mon = (qw/jan feb mar apr may jun jul aug sep oct nov dec/)[(localtim
+e)[4]];
print "$mon\n";
| [reply] [Watch: Dir/Any] [d/l] |
Re: Localtime
by fredopalus (Friar) on Feb 14, 2003 at 23:18 UTC
|
$month = lc(substr(scalar localtime, 4, 4));
You may also wan't to look at localtime. | [reply] [Watch: Dir/Any] [d/l] |
A reply falls below the community's threshold of quality. You may see it by logging in. |