Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

filemtime - GMT or local (server) timestamp

Tags:

php

filemtime — Gets file modification time

This function returns the time when the data blocks of a file were being written to, that is, the time when the content of the file was changed.

My question: is filemtime returning:

  • gmt timestamp (modification time) of the file (like time() ) ?
  • or local server timestamp of the file?

EDIT: probably the definition of "timestamp" is same as time() (This count starts at the Unix Epoch on January 1st, 1970 at UTC)

like image 791
ihtus Avatar asked Mar 20 '23 20:03

ihtus


2 Answers

The filemtime function returns a timestamp, which is to say it returns the number of seconds since the Unix Epoch. Timezones are inconsequential to timestamps; Midnight 1/1/1970 UTC happened simultaneously everywhere, afterall. Timezones represent an offset to be applied to this amount of seconds in order to reach the relative time for the region.

In other words, if you look at the integral value of a timestamp, change your timezone, and look at it again, it'll still be the same number. The difference comes when you use a function like date() to format that number to a timezone-relative date/time. See this comment on the usage of time().

like image 63
blakeo_x Avatar answered Apr 02 '23 17:04

blakeo_x


The filemtime function returns a Unix time stamp, which is UTC. This is per definition, since Unix timestamps represent the amount of seconds expired since Midnight 1/1/1970 UTC. time() similarly is a Unix timestamp, so filemtime values can be compared directly to it without any timezone considerations.

(I provided this additional answer because when I arrived here by Google, I found the other one a bit hard to understand - I hope someone else will find the brevity helpful)

like image 32
E. T. Avatar answered Apr 02 '23 15:04

E. T.