neilsolent
2009-10-28 10:00:32 UTC
Hi All
How can I read/write 4-byte wide timestamps to files in GMT, ignoring
any local timezone?
i.e. I want versions of utime() and stat() that work only in GMT.
To demonstrate what I mean..
Run this program in the UK at 01:59 on 25/10/09 (when the local
timezone is GMT+1):
<code>
#include "stdafx.h"
#include <sys/utime.h>
int main(int argc, char* argv[])
{
struct _utimbuf ver;
ver.modtime = 0;
ver.actime = 0;
_utime("test", &ver);
return 0;
}
</code>
C:\temp>dir test
Volume in drive C has no label.
Volume Serial Number is 5028-7113
Directory of C:\temp
01/01/1970 00:00 7 test
1 File(s) 7 bytes
0 Dir(s) 34,768,842,752 bytes free
Wait 2 minutes (local timezone changes to GMT+0) and:
C:\temp>dir test
Volume in drive C has no label.
Volume Serial Number is 5028-7113
Directory of C:\temp
31/12/1969 23:00 7 test
1 File(s) 7 bytes
0 Dir(s) 34,768,842,752 bytes free
This differs from how utime() works on UNIX. The UNIX man pages say:
" The times contained in the members of the utimbuf structure
are measured in seconds since 00:00:00 UTC, January 1, 1970. "
The Windows version seems to be taking into account the current
timezone when these commands are run. I need to turn this behaviour
off.
Thanks,
Neil
How can I read/write 4-byte wide timestamps to files in GMT, ignoring
any local timezone?
i.e. I want versions of utime() and stat() that work only in GMT.
To demonstrate what I mean..
Run this program in the UK at 01:59 on 25/10/09 (when the local
timezone is GMT+1):
<code>
#include "stdafx.h"
#include <sys/utime.h>
int main(int argc, char* argv[])
{
struct _utimbuf ver;
ver.modtime = 0;
ver.actime = 0;
_utime("test", &ver);
return 0;
}
</code>
C:\temp>dir test
Volume in drive C has no label.
Volume Serial Number is 5028-7113
Directory of C:\temp
01/01/1970 00:00 7 test
1 File(s) 7 bytes
0 Dir(s) 34,768,842,752 bytes free
Wait 2 minutes (local timezone changes to GMT+0) and:
C:\temp>dir test
Volume in drive C has no label.
Volume Serial Number is 5028-7113
Directory of C:\temp
31/12/1969 23:00 7 test
1 File(s) 7 bytes
0 Dir(s) 34,768,842,752 bytes free
This differs from how utime() works on UNIX. The UNIX man pages say:
" The times contained in the members of the utimbuf structure
are measured in seconds since 00:00:00 UTC, January 1, 1970. "
The Windows version seems to be taking into account the current
timezone when these commands are run. I need to turn this behaviour
off.
Thanks,
Neil