John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

The -M operator gives how old a file is, in days. Add that to $^T (after converting to a common representation) and this produces the file's timestamp.

Well, almost. It gives it in local time. If I repeat the measurement on the same file six months later, I find the times differ by an hour even though the file has not been touched.

What I really want is the absolute (in UTC) modification time of a file. Is there a simple way of doing that in Perl without calling Win32-specific functions?

—John

Replies are listed 'Best First'.
Re: Getting Absolute File Time-Stamp?
by Fletch (Bishop) on Jan 23, 2004 at 21:30 UTC

    Presuming Wintendo is at all sane, perldoc -f stat.

      Ah, the field in stat returns the time in seconds since 1970, In GMT. So it will be the same regardless of the time zone. I assumed that the dash operators returned the same stuff that was in stat, but the stat gives the data in a different format, and is what I want here. Also, the docs for $^T didn't mention GMT (or UTC), but I suppose it is.

      Only thing is, the value is rounded to the nearest second! I would have expected it to return decimal places based on the available accuracy of the file system.

        Only thing is, the value is rounded to the nearest second! I would have expected it to return decimal places based on the available accuracy of the file system.

        The number of seconds since the 0th second on January 1st, 1970 is a common unix time stamp. That's why it doesn't "return decimal places based on the available accuracy of the file system". Because it's a *nix time stamp, not a universal time stamp (although it is often used as such)

Re: Getting Absolute File Time-Stamp?
by Skeeve (Parson) on Jan 23, 2004 at 22:10 UTC
    How about using gmtime($^T+ -M) ?