Liquid - Show current time based on specific time zone

Hi everyone!

In Shopify I can use the snippet {{ “now” | date: “%H:%M” }} to show the current time in my timezone.

In Liquid I can use the same snippet but with a filter {{ “now” | in_time_zone: “Europe/Copenhagen” | date: “%H:%M” }} to show the time in a specific timezone, no matter where the visitor is located in the world.

But that filter is apparently not supported by Shopify!

Is there any way to show the current time in a specific timezone in Shopify?

I hope it is possible in Liquid, because I am going to use the output in a Liquid if-function.

Basically what I need is the following: {% assign current_hour_cph = CURRENT HOUR IN CPH %}

Thank you!

You should look to use JavaScript instead. If you use the Liquid “now” it won’t give you current time, but rather the time in which that page was cached. It’s possible for a shop to not need a cache clearing for hours so your time will be erratic - and wrong.

It’s not so much that it’s unsupported, more that the cache works against you.

Hi Jason.

Thank you, that is a great answer!

I’m really not so experienced in combining Liquid and JS.

Can you give me a clue how to do this?

I found a javascript snippet posted by Diego_ezfy at https://community.shopify.com/c/technical-q-a/how-to-get-the-local-time-with-liquid/m-p/841895/highlight/true#M31583 that includes the following Javascript example which I am adding here for reference:

#