How to get the local time with Liquid ?

Solved
Highlighted
New Member
2 0 0

I have trid to add the local date & time with it {{ "now" | date: "%b %d, %Y %H:%M" }}.

But got a time from wront timezone GST +0000  "Aug 14, 2020 05:13".

I'am in Singapore, GST +0800.  The right time is "Aug 14, 2020 13:13".

So how to get the local time with Liquid?

Thanks so much.

0 Likes
Highlighted
Shopify Partner
565 89 130

Hello @DevPat, your liquid syntax is correct. check your pc or laptop time. I think It is wrong

if the useful mark as like and accept the solution

 

0 Likes
Highlighted
Astronaut
1074 173 210

This is an accepted solution.

@DevPat 

Not exactly what you asked for but, alternatively, you can use Javascript. Add this after the <body> in your theme.liquid for the sake of example.

  <h1 id="timeNow"></h1>
  <script>
    const el = document.getElementById(`timeNow`);
    el.textContent = new Date();
  </script>

 

◦ Problem Solved? ✔️ Please click on Accept as Solution and like.
◦ Hire me! Recommended by 25+ customers on Facebook. Click here to read their reviews.
◦ Contact me at: diego.boarutto.fortes@gmail.com
1 Like
Highlighted
New Member
2 0 0

I have check my pc ,it 's okay.

And I tried to change the computer and the problem still exists.

Can I set up the timezone in it ?

0 Likes
Highlighted
Astronaut
1074 173 210

@DevPat What time is it showing for you?

This code gets the timezone based on the IP address of your computer. Therefore, if you're in Singapore, theoretically it should show you the local time in Singapore. Are you using a VPN or something like that? Also, can you try it on your mobile phone as well and send a screenshot of what time it shows?

Thanks.

◦ Problem Solved? ✔️ Please click on Accept as Solution and like.
◦ Hire me! Recommended by 25+ customers on Facebook. Click here to read their reviews.
◦ Contact me at: diego.boarutto.fortes@gmail.com
0 Likes