
Borderline
Deleted
Jan 22, 2000, 3:19 AM
Post #6 of 6
(529 views)
|
|
Re: need script for time stamp for EST (USA)
[In reply to]
|
Can't Post
|
|
Hi, I am sorry I did not explain it better. This block of code should replace what you have totaly. I was assuming you wanted the time in this format 6:04 AM Let me know if this is not correct. Also I am not sure where your time code fits into your program as a whole so I will write an entire program here to show you how this works. <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> #!/usr/bin/perl -w # Here I am calling a subroutine with the # parameter -3. -3 is the offset from the # machine that is running it to the time # zone I want the time returned in. With the # print statement before it it will just print # the return value. print getTime(-3); # Here is the subroutine getTime. It takes # the -3 I passed to it and stores it in # $offset and returns the time formated sub getTime { # When you pass a variable to a # subroutine it is stored in the # global array @_. shift defaults # to shifting elements from @_ if # no array is given my $offset = shift; # Here I am using the offset times # the number of seconds in an hour # plus the return from the time() # function call and then passing the # whole thing to localtime. # localtime returns a 9 element array # I just want certain elements so I # specifing element 1,2,3,8 and then # setting those into the coresponding # variables my ($min,$hour,$mday,$isdst) = (localtime(time()+$offset*3600))[1,2,3,8]; # This part is a little complicated # but it basicaly puts it in the format # 6:17 AM my $time = sprintf("%2d:%02d %2s",($hour % 12 or 12)+$isdst,$min,$hour>11?"PM":"AM"); # now we just return the value in $time # which is formated like we want it return $time; } </pre><HR></BLOCKQUOTE> If you copy and past this into a file and run perl on it you will get the output of time formated like 6:23 AM I really hope this helps you. If you are still confused post your whole program here so I can look at what you want to do. Scott
|