The original post: /r/linux by /u/HorkusSnorkus on 2024-12-23 20:48:08.

For those of you who use Linux, or know people who do. Nerdliness follows but will save those in the know a bunch misery …

I just noticed that, suddenly, date/timestamps were off by hours when I mounted an SD card. This may have been happening for a while and I just didn’t notice.

The particular example that triggered this was digital photo files, but this problem likely adheres to all file types.

I confirmed the problem wasn’t camera specific, and that MacOS didn’t have it so … all roads pointed to Linux itself.

By way of background, SD cards normally store the time/date in local time. But Linux stores everything timestamped in UTC/GMT time. It then uses an timezone offset to say, “Oh, you live near <some place>, that’s UTC-7” and adjusts accordingly so the time/date makes sense to the local user.

In the past, Linux was smart enough to know the difference between locally timestamped files and SD card files but, apparently, a recent an older kernel update no longer does this (for reasons I have yet to explore).

The big hint here was that a file on an SD card would end up with a timestamp that was exactly 7 hours earlier than local time. i.e., It was applying the timezone offset from UTC to the SD card files on the assumption that the files there had been timestamped with UTC time … which, as I said, is wrong. Devices pretty much universally timestamp SD card files with local time.

Although the Linux kernel digirati haven’t sorted this out, there is a fairly simple fix. When mounting an SD card on Linux - whether by hand or via an automounter of some kind, be sure to add the following to the mount command, adjusting, of course, for how many minutes your local time is offset from UTC - mine reflects UTC-7:

time_offset=-420