Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: Getting the timestamp of a file

by becca23 (Novice)
on Jul 30, 2008 at 15:53 UTC ( [id://701166]=note: print w/replies, xml ) Need Help??


in reply to Re: Getting the timestamp of a file
in thread Getting the timestamp of a file

localtime( (stat $file)9 ) doesn't work for me. I get Wed Dec 31 18:00:00 instead of Wed Jul 30 10:47:00. Also, i use the local time module to build a time function to tell me what time it is, and anytime the use::localtime module is active and i use the localtime function i get errors.

Replies are listed 'Best First'.
Re^3: Getting the timestamp of a file
by jettero (Monsignor) on Jul 30, 2008 at 16:00 UTC
    I suspect the time returned by localtime is correct and the time returned by whatever you think is doing it accurately is not. If it were purely a timezone issue it wouldn't be off by 47 minutes.

    -Paul

Re^3: Getting the timestamp of a file
by massa (Hermit) on Jul 30, 2008 at 16:09 UTC
    $ ls -l monlog.txt -rw------- 1 h h 10755194 2008-05-30 12:59 monlog.txt $ perl -le 'print scalar localtime((stat)[9]) for @ARGV' monlog.txt Fri May 30 12:59:45 2008 $ perl -MFile::stat -le 'print scalar localtime(stat($_)->mtime) for @ +ARGV' monlog.txt Fri May 30 12:59:45 2008
    Worked pretty well here. What do you mean with "i use the local time module to build a time function to tell me what time it is, and anytime the use::localtime module is active and i use the localtime function i get errors"?? If you have a local "localtime.pm" module, change its name and the name of the "faux-localtime" function, because it's not good practice to clobber core functions' names.
    Update: used File::stat like becca23 did.
    []s, HTH, Massa (κς,πμ,πλ)
      In the hope of clearing some (potential) confusion here... I think becca23 is referring to Time::localtime (which is where ctime is defined), which is of course not the same as localtime. Nevertheless, using your one-liner, I get the same answer with both functions (which is a GoodThing).

      $ ls -l xyz.txt -rw-rw-r-- 1 x x 0 Jul 30 12:22 xyz.txt $ perl -le 'use Time::localtime; print ctime((stat)[9]) for @ARGV' xyz +.txt Wed Jul 30 12:22:28 2008 $ perl -le 'print scalar localtime((stat)[9]) for @ARGV' xyz.txt Wed Jul 30 12:22:28 2008
      ...still suspecting a time zone issue, but puzzled/worried by the 47 minute discrepancy, to say nothing of the approx 5 month discrepancy that comes with it...
Re^3: Getting the timestamp of a file
by moritz (Cardinal) on Jul 30, 2008 at 15:58 UTC
    localtime usually works pretty well. If it doesn't, chances are that you're doing something seriously wrong.

    But of course without seeing any code we can't tell.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://701166]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-03-29 02:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found