Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Getting the timestamp of a file

by jettero (Monsignor)
on Jul 30, 2008 at 15:38 UTC ( [id://701163]=note: print w/replies, xml ) Need Help??


in reply to Getting the timestamp of a file

I'm not as familiar with ctime, I always use localtime, so it'd be  $stamp = localtime( (stat $file)[9] ); I believe that will sort out the DST issues for you automatically.

-Paul

Replies are listed 'Best First'.
Re^2: Getting the timestamp of a file
by becca23 (Novice) on Jul 30, 2008 at 15:53 UTC
    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.
      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

      $ 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...
      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://701163]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-03-28 09:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found