Converting epoch in filename to datetimeoriginal in local timezone

Started by rohithvsm, January 30, 2023, 11:15:27 PM

Previous topic - Next topic

rohithvsm

I have a directory with file names in the following format:
img_<epoch in nano seconds>_photo.jpeg
e.g. img_1673293150443146_photo.jpeg
I want to set the datetimeoriginal tag using the epoch in the file name. I found a way to do it from another post here: https://exiftool.org/forum/index.php?msg=60840.
This sets the datetimeoriginal in UTC as epochs are always in UTC.
But, when I upload these photos to Google Photos, they show up with the time being interpreted in the local time zone. It is probably due to the timezone information missing in the tag.
How can I set the datetimeoriginal tag to include the timezone information or adjust it to the local or a specific timezone?

$ exiftool -time:all -s img_1673639103879287_photo.jpeg
FileModifyDate                  : 2023:01:22 10:27:58+05:30
FileAccessDate                  : 2023:01:31 00:43:08+05:30
FileInodeChangeDate             : 2023:01:22 17:26:02+05:30
$ exiftool '-alldates<${filename;/(\d{10})/ and $_ = $1}' -d %s img_1673639103879287_photo.jpeg
    1 image files updated
$ exiftool -time:all -s img_1673639103879287_photo.jpeg
FileModifyDate                  : 2023:01:31 00:43:52+05:30
FileAccessDate                  : 2023:01:31 00:43:54+05:30
FileInodeChangeDate             : 2023:01:31 00:43:52+05:30
ModifyDate                      : 2023:01:13 19:45:03
DateTimeOriginal                : 2023:01:13 19:45:03
CreateDate                      : 2023:01:13 19:45:03
When uploaded to Google Photos, it shows up as below:
Jan 13
Fri, 7:45 PM GMT+05:30
img_1673639103879287_photo.jpeg
I would like it to be in the local or Pacific timezone instead which would be Fri, 11:45 AM GMT-08:00.

Phil Harvey

This should work:

exiftool '-subsecdatetimeoriginal<${filename;$_ = /(\d+)/ ? ConvertUnixTime($1 * 1e-6,1,6) : undef}' img_1673639103879287_photo.jpeg

A few things to note:

1. Your time stamp is in microseconds not nanoseconds.

2. The \d{10} from the other post doesn't work because your timestamp contains more digits.

3. I'm writing Composite:SubSecDateTimeOriginal to set EXIF:DateTimeOriginal as well as OffsetTimeOriginal and SubSecTimeOriginal.

4. The advanced formatting expression uses an internal ExifTool ConvertUnixTime routine.  The time is converted to local time if the second argument to this call is non-zero (I've used "1" here).  The third argument specifies the number of digits to return in the fractional seconds.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).