Skip to content

Instantly share code, notes, and snippets.

@smeech
Last active October 13, 2025 09:49
Show Gist options
  • Select an option

  • Save smeech/b9f1e793cf63ee42e8512450ae85dc98 to your computer and use it in GitHub Desktop.

Select an option

Save smeech/b9f1e793cf63ee42e8512450ae85dc98 to your computer and use it in GitHub Desktop.
[Date_Time] Espanso trigger to output time and date in another timezone. Requires Python and its pytz library. Somewhat redundant from Espanso v2.3.0. #espanso #python
# Espanso trigger to output time and date in another timezone
# Requires Python and its pytz library
matches:
- trigger: :tzdate
replace: '{{output}}'
vars:
- name: zones
type: script
params:
args:
- python
- -c
- |
import pytz
print("\n".join(pytz.all_timezones))
- name: zone_choice
type: form
params:
layout: 'Pick a time-zone: [[zone]]'
fields:
zone:
type: list
values: '{{zones}}'
default: Europe/London
- name: output
type: script
params:
args:
- python
- -c
- |
import pytz; from datetime import datetime
timezone = pytz.timezone('{{zone_choice.zone}}')
# Get the current date and time in UTC
utc_now = datetime.utcnow().replace(tzinfo=pytz.utc)
# Convert UTC time to the specified timezone
local_time = utc_now.astimezone(timezone)
print("Current date and time in", timezone, "is:", local_time.strftime('%F %T'))
@smeech

smeech commented Feb 6, 2025

Copy link
Copy Markdown
Author

i did the same ๐Ÿ˜† ... it's just way faster with the internal data type, and not as wasteful ...

# this IS discouraged, yet this is not a web app, this is a one-shot tool.

    locale.setlocale(locale.LC_ALL, ".".join(locale.getlocale()))

works here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment