Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gmmastros on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I print the current date/time?

Status
Not open for further replies.

sloppyhack

Technical User
Apr 17, 2001
111
0
0
US
Stupid question I'm sure, but I need to print the current date and time from the system to the log files I am printing to. Any help would be greatly appreciated. Stillflame where for art thou. I am just adding the bells and whistles to my script at this point! It is kicking arse.

Sloppy
 
[tt]my ($sec, $min, $hour, $wday, $month, $year, $yday, $something) = localtime(time())[/tt]

i think that's right. do a 'perldoc -f localtime' just to be sure "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
I tried it and it doesn't seem to work. I get:
LOG FILE
FILE: EMG_test
DATE: 2-1-4
TIME: 28:43
when I input:

print LOG " LOG FILE\n";
print LOG " FILE: ",$file,"\n";
print LOG " DATE: ",$month,"-",$wday,"-",$year,"\n";
print LOG " TIME: ",$hour,":",$min,"\n";

Very odd. Any ideas oh mighty one?

Slop
 
well, i don't have perl on the computer i'm on right now, so check with the perldocs (i probly missed an entry in the array of values localtime returns - sorry). oh, and one thing you should also note: wday, yday and month start at 0, not 1. and you have to add 1900 to the year to get it to be correct.

(oh, and 'mighty one' - LOL - not what i would choose in addressing me. something more like 'oh he who has way too much free time for this sorta thing' :) ) "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
Never mind Stillflame. I looked into "localtime" and figured it out. The output was y2k compliant and needed a little tweeking. It works great!!!

Thanks again!!!!!!

The sloppy one.
 
I'm glad you have the free time. You have really been a big help to me. This was the line that was needed (you weren't far off) and a little tweeking of the values to get to normal time/date:

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

Almost finished with my hack. Thanks a bunch.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top