Convert Time in Region to Local Timezone
There is no time,
but we have timezones.
[unknown zen apprentice]
{convenience time timezones}
I want something in Emacs to convert a time string containing a timezone to the local timezone on my machine.
Possibly program date
can do this. ISTR that the fsf page
proposed date
to do such conversion in the context of a
worldwide conference so the participants can easily check the time in
their local timezone.
Let's check some of date
's abilities.
$ date --date='18:30 january 27, 2021 PST'
Thu Jan 28 03:30:00 CET 2021
Nice, but I don't want the timezone specifier. I don't need it. It's been converted in my normal time. I don't want that extra text.
$ date --date='18:30 january 27, 2021 PST' +"%Y-%m-%d %H:%M" 2021-01-28 03:30
Great! LGTM.
So let's rely on date
for the hard work.
Functionality code
(defun mw-region-time-in-local-tz (start end) "Interpret region START END as time. Show time in local timezone. Example(-!- is point, -m- is mark): given: -!-18:30 january 27, 2021 PST-m- action: { M-x mw-region-time-in-local-tz RET } result (note: the local zone is CET): see the message '2021-01-28 03:30' in the minibuffer. " (interactive "r") (message "%s" (shell-command-to-string (concat "date --date='" (buffer-substring-no-properties start end) "'" " +'%Y-%m-%d %H:%M'"))))
Meta
Please use the features of gitlab for comments etc. See e.g. https://gitlab.com/marcowahl/emacs-blog-mw/-/issues/ .
Share under CC BY-SA 4.0.