What’s the correct way to convert `Dates.unix2datetime(mtime(fpath))` to a datetim

What’s the correct way to convert Dates.unix2datetime(mtime(fpath)) to a datetime with the correct time zone for my system? I get a time 5 hours in the future, so I assume it’s returning UTC.


julia> Dates.unix2datetime(mtime(fpath))
2021-01-31T22:46:14.370

julia> Dates.now()
2021-01-31T17:46:23.646

Note that the original poster on Slack cannot see your response here on Discourse. Consider transcribing the appropriate answer back to Slack, or pinging the poster here on Discourse so they can follow this thread.
(Original message :slack:) (More Info)

1 Like

Posting the answer from the slack discussion.

For this particular case, there was a requirement to only use functions in Base (which doesn’t include the Dates stdlib, or the TimeZones package)

Using functions only in Base:

julia> Base.Libc.strftime("%FT%R%Z", mtime(fpath))
"2021-02-01T01:15CET"
julia> Base.Libc.strftime("%FT%R%z", mtime(fpath))
"2021-02-01T01:15+0100"
2 Likes