Skip to main content

Make it easier to display Dates and Times in site visitor's timezone

Currently Liquid can be used to display the UTC times from the database in a particular timezone:
{{this['Date Field'] | strftime: "%A %d %B at %I:%M %p %z", "Australia/Darwin"}}
But if you want to work out the visitor's timezone, it's necessary to implement a JS solution.
Graham Boyd has requested we build a feature which uses best practice JS but is quick to implement and re-usable.

3 comments

Log in to comment and vote

Comments3

  • Matt Walter changed status to Open
    Team•

    Apr 6, 2022

  • Jon Macmorland

    •

    Jan 12, 2022

    Could this also allow for the switch between GMT & BST

  • Matt Jones

    •

    May 27, 2020

    We're still deciding the best solution for this one.
    To help us work out what's most useful, I'd just like to poll the voters on this feature- how would you prefer to specify the format for the date/time?
    If there was a Liquid tag like:
    {% include "local_date", date: this['Date of Sale'], format: "" %}
    And you wanted to output 2020/05
    Would you prefer to specify format with:

    • JavaScript Syntax e.g. t.getFullYear()+t.getMonth()).slice(-2)+'/'+t.getDate()).slice(-2) etc. where any strings are taken literally
    • Liquid syntax "%Y/%m" …where any characters not in the format "%x" are taken literally.
    • Or, alternatively, would you rather not specify an exact format at all, but instead use JavaScript which finds the local time format automatically based on timezone/ location?
      In all other Liquid contexts, you'd use the Liquid syntax, however since this Liquid parameter is destined to be run on a JavaScript variable, it might make more sense to input a JavaScript function to handle format.