Utcnow() doesn't print UTC time?

In this thread I asked for help on a time zone conversion and documented my solution, which relied on using utcnow() in a template to get the current UTC date/time in timestamp format that can then be dynamically adjusted based on time zone data from my mobile device.

That was working great but last time I changed time zones I noticed that my watch was not updating the date at the right time. Investigating further led me to discover that utcnow() no longer prints the UTC time and instead prints the time in the time zone I have configured in my configuration.yaml file like so:

  time_zone: America/Los_Angeles

I probably need to file a bug report for this as it seems like it must be a bug, but wanted to check in and see if anyone else can confirm this in their instance first or if it might just be something wrong on my end. To replicate you can just drop the following template into the dev tools template page and see if you get get the proper UTC time or not:

{{ as_timestamp(utcnow())  | timestamp_custom("%I:%M:%S %p %b/%d/%Y") }}

utcnow() is working as it should, but you need to specify that local time is false in the timestamp_custom and while you’re at it, get in the habit of setting a default since it will be required next month.

{{ utcnow() | as_timestamp | timestamp_custom("%I:%M:%S %p %b/%d/%Y", False, "00:00:00 AM 1/1/01") }}

From the docs:

Filter timestamp_custom(format_string, local_time=True, default) converts an UNIX timestamp to its string representation based on a custom format, the use of a local timezone is default.

See Also:

Ah ok that would explain it, had a feeling it was something like that since it had been working fine before an update. Just tested and confirmed it’s working properly now so thanks.