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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mtime manipulation 1

Status
Not open for further replies.

icetnet

IS-IT--Management
Joined
May 9, 2007
Messages
2
Location
US
I like the output of the $mtime variable in the stat array.

print scalar localtime($mtime);
or
print scalar gmtime($mtime);

Tue May 8 19:56:35 2007

however, I need it in the format of

Tue, May 8 2007 19:56:35

how would I manipulate this? I'm smart enough to be stupid here.
 
you can use the POSIX module and the sftime function, or:

Code:
my ($wd,$m,$d,$t,$y) =  (split /\s+/,localtime(time))[0..4];
print "$wd, $m $d $y $t";

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
use $mtime in place of time in the above code.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Thanks Kevin,

I forgot to mention that I needed the code to be as portable as possible. I didn't even think of using split. Good call. Works great on the platforms I've tested so far.

Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top