CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
A Time thingy

 



SirAnvil
Deleted

Feb 9, 2001, 3:57 PM

Post #1 of 7 (1159 views)
A Time thingy Can't Post

Here is one just for fun... I use this code to get the julian date and post it to a file.

($sec, $min, $hours, $mday, $month, $year, $wday, $yday, $isdst) =
localtime();

I got this form perlarchive of course :-) <love = "this forum">

So I print $yday to a file.

Now, how about this. We take the $yday from that file a few months down the line and decide to convert it back into a legable date format like

1/12/2001

Hmmmmm

SirAnvil
www.christiangamers.org


muinatit
Deleted

Feb 9, 2001, 4:18 PM

Post #2 of 7 (1157 views)
Re: A Time thingy [In reply to] Can't Post


Code
### 
sub GetDate {
###
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
$mon = $mon+1;
$mon = "0$mon" if ($mon < 10);
$mday = "0$mday" if ($mday < 10);
$year = ($year % 100);
$year = "0$year" if ($year < 10);
$date = "$mon.$mday.$year";
}

muinatit
muinatit@hotpop.com


muinatit
Deleted

Feb 9, 2001, 4:21 PM

Post #3 of 7 (1157 views)
Re: A Time thingy [In reply to] Can't Post

Actually the code above will put it into something like...

02.09.01

But the code is pretty self explainatory and you could modify it to your likes pretty easily.

muinatit
muinatit@hotpop.com


SirAnvil
Deleted

Feb 10, 2001, 3:29 PM

Post #4 of 7 (1152 views)
Re: A Time thingy [In reply to] Can't Post

That's great....

What if all I have is the Julian day? I know I can get the julian day from #yday listed above, but what if that is all I have. How then do I convert 'that' into a date?

SirAnvil
www.christiangamers.org


muinatit
Deleted

Feb 11, 2001, 6:22 PM

Post #5 of 7 (1128 views)
Re: A Time thingy [In reply to] Can't Post

You'd probably need to set up a hash of the months and their dates.


Code
%months = ( 
January => 31,
# ect.
);

Sorry for my bad setup. Compare the $yday against that. Too indepth stuff for me to try. :\

Jeffrey "muinatit" Lamoureux
muinatit@hotpop.com


Jasmine
Administrator / Moderator

Feb 12, 2001, 12:08 AM

Post #6 of 7 (1126 views)
Re: A Time thingy [In reply to] Can't Post

From the FAQ: How can I find the Julian Day?



japhy
Enthusiast

Feb 12, 2001, 10:32 AM

Post #7 of 7 (1121 views)
Re: A Time thingy [In reply to] Can't Post

If you know what year you have, and you have a day of the year, you can do a simple calculation:


Code
use Time::Local; 

my $year = 2001;
my $yday = 100; # or (localtime)[7], for the actual number
my $beginning = timelocal(
0,0,12, # represents noon
1, 0, $year - 1900 # represents Jan 1, $year
);

my $seconds_to_now = 86400 * $yday;
my @data = localtime($seconds_to_now + $beginning);

And voila, the @data array holds the information you requested.

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives