The issue is that FAT filesystem stores its timestamps using localtime.
The linux kernel runs on UTC time.
Normally, the timezone is purely a userspace thing. Under linux, different users could be logged into the same computer from many different timezones, and this is why the kernel runs in UTC time and the users timezone setting determines the local time.
Most linux filesystems also keep their filesystem timestamps in UTC time as well.
However, the FAT filesystem stores its filesystem timestamps in local time.
The timestamp on the sdcard is most likely correct, and if you put the sdcard on a windows machine, then it will show correctly. In order for linux to display the time correctly, the kernel needs to be told what the current timezone is.
I verified this on 3 of my linux computers, I wrote a small C program:
Code: Select all
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/time.h>
int main(int argc, char **argv ) {
int rc;
struct timeval tv;
struct timezone tz;
memset(&tv, 0, sizeof(tv));
memset(&tz, 0, sizeof(tz));
rc = gettimeofday(&tv, &tz);
if (rc == 0) {
printf("tv.tv_sec = %ld\n", tv.tv_sec);
printf("tv.tv_usec = %ld\n", tv.tv_usec);
printf("tz.tz_minuteswest = %d\n", tz.tz_minuteswest);
printf("tz.tz_dsttime = %d\n", tz.tz_dsttime);
} else {
printf("gettimeofday failed, errno = %d\n", errno);
}
return 0;
}
and on 3 of my computers (all running Ubuntu 16.04) I got this output:
Code: Select all
tv.tv_sec = 1490636674
tv.tv_usec = 498363
tz.tz_minuteswest = 0
tz.tz_dsttime = 0
and ls -l /media/dhylands/PYBFLASH showed the micropython filesystem timestamps as 7 hours in the future.
If I then did
and reran my gettimeofday C program then I got:
Code: Select all
tv.tv_sec = 1490636725
tv.tv_usec = 276087
tz.tz_minuteswest = 420
tz.tz_dsttime = 0
and now ls -l /media/dhylands/PYBFLASH showed the correct time. Normally, the call to hwclock --systz should be in one of the system startup files, and I'm not sure why it isn't happening. So some further investigation is due.