How to get current time?

I am trying to set text as the current time, have it set to this variable [[Now.getHours()]]:[[Now.getMinutes()]] [[Now.toLocaleTimeString().slice(-2)]], but it’s displaying the time as ‘13:17PM’ when I want it to display as ‘1:17 PM’

You can convert to 12 hour time by doing:

[[Now.getHours() % 12]]

The modulo operator gives you the remainder after division. So in this case, 1.

2 Likes

In my experience, date (and time) formatting depends on how the web browser respect and follow your computer’s locale settings. Some browsers are more reliable than others, and I suggest you try a plain Now.toLocaleTimeString() in a couple of browsers just to get an idea of where your bet is best placed. If you cannot stick with “the best” browser, for example if you’re doing user testing on user’s computers, then this approach may not be relevant (although most people have more than one browser on their computer).

Happy prototyping!