Rahul Rahul - 1 year ago 146
C++ Question

Does _finddata_t structure return time_write as system time or it is influenced by session timezone?

I am referring the documentation of

APIs here

These APIs return file information in a _finddata_t structure. I need to access file modification time from
element. Though documentation says that
time is stored in UTC format (It is a times stamp). Documentation doesn't clarify if this time represents local time or UTC time. It seems to me that
doesn't return the UTC time instead its value is influenced by the system time zone settings.

My Question is - Does
returns local time represented in the UTC timestamps ?

Here I explain what actually I am trying to understand. My system is in IST timezone. Now, there is a file
for which windows shows

Date Created - 10/21/2016 10:51 AM

Date Modified -10/21/2016 10:51 AM

I used epoch converter to find out the the epoch timestamp for which it turn out to be as following -

Local time to epoch conversion

Now if I retrieve the
element from
structure which has been returned by
for the same file i.e.
. I expect the returned timestamp should be close to

Epoch timestamp 1477027260 as shown in the image above.

But I get the time_write as 1477043509

If I again use epoch converter I get the following
epoch to local time

I am trying to understand why there is 4:30 Hours of time difference in GMT in both images shared above? IMO timestamp should have been almost same. What obvious I am missing here ?

For those folks who were asking for sample code. Here I paste link of another post which I had asked a year ago for the same reason but scenario was little different, There I was referring to _stati64 struct. I didn't troubleshoot the problem further at that time. By now it is pretty clear that
_finddata_t and _stati64 APIs are affected by _tzset environment variable as Harry mentioned in this post while FILETIME struct is not.

Answer Source

To troubleshoot further, next I used GetFileTime API to retrieve the the file modification time in FILETIME struct and converted the time into UTC timestamp. I got the time according the time set on my computer. I was expecting the same.

At this point I started investigating the way we execute our program through a perl script. I found that perl script was setting the timezone to GMT-1.
Since my computer was in timezone GMT+5:30, therefore I used to get resultant +04:30 hrs of difference as mentioned in the original post.

Therefore I would like to sum up my experience as - the outcome of _finddata_t strcut is affected by the timezone set in the session but the outcome of FILETIME struct is not affected by the time zone set in the session, instead it is the time according the system timezone. Since I was retrieving one time using FILETIME struct and another using _finddata_t strcut that was causing the problem. Took me ~48Hrs to find out this interesting observation.

Why does that happen? Perhaps the answer is provided by Harry in the comment section.I am pasting the same here as it is -

changing the timezone in Perl is probably causing the TZ environment variable to be set, which affects the C runtime library as per the documentation for _tzset. It isn't a per-session setting, at least not in the way Windows uses the word "session"."

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download