How can I change the timezone of current date/time?

I’m working on a date/time selector feature that works great, with one caveat. I need the timezone to be dynamically selected. I am using the Dates Generator plugin, which requires Current date/time, but I can’t switch it to a dynamic timezone. Anyone have insight? I tried rounded down to and then selecting timezone, but no luck there.

Rounding down by timezone should work. Do you also have enable timezone override controls enabled in your app Settings > General?

@parthapatel0723 Yeah, that’s a real limitation :sweat_smile: the Dates Generator plugin always sticks to the app’s default timezone and won’t switch dynamically. You can store the user’s timezone/offset and adjust the date with math or a quick Toolbox JS conversion before using it. Unfortunately, there’s no native dynamic-timezone option in the plugin right now.

1 Like

Yup, tried but it’s messing up with times, perhaps how the plugin is publishing the time values. In the screenshot the time on the chip is with the selected timezone as the timezone (PST) for the formatting, and the plain text above is the straight date from the plugin (EST). For EST, it’s returning normal intervals from 12AM to 11PM, but for the formatted date with the timezone (rounded down) it’s cutting times.

Ah okay, good to know. Man, it sucks that dates are a limitation, my app is heavily reliant on it and especially sucks because it’s heavily reliant on dynamic timezones :slight_smile: .

Do you have any guide to point me to on using Toolbox JS? Honestly, thinking about just hopping in plugin editor and putting my own solution together!

What exactly to you mean by ‘Change the Timezone of the Current Date/Time’?

Current Date/Time is a timestamp of NOW (this very moment) - so timezones don’t apply (unless you’re displaying that date somewhere) - so it’s not clear what you mean.

Maybe you mean ‘Create a new date object, based on the Current Date/Time, as defined in a particular timezone, but changed to a different timezone?

i.e.

If the Current Date/Time is 20th Feb, 11:22am in New York, create a new Date object which is 20th Feb, 11:22am in London time?

Is that what you’re trying to do?

Or something else?

1 Like

Yes, sort of.

I’m using the Dates Generator plugin. The plugin requires an input of “Current Date/Time” as mentioned in the field documentation. I want the current date/time to be of a certain timezone.

For ex. I am in NY (EST) but if I select another timezone (ex. PST) from a dropdown, I want the Dates Generator to create dates/times in PST.

The idea is that the current user can schedule a start date/time and end date/time in another timezone (the current user is a service provider that travels for their client).

That doesn’t make sense.

The Current Date/Time is the current Date/Time

It doesn’t have a timezone (unless you’re displaying it somewhere).

But.. if you want to create a different Date - not the Current Date/Time but a new Date, with the same Day/Month/Year/Hour/Minute/Second as the Current Date/Time (in the User’s Device Timezone) but in a different timezone defined by the user - there is no (simple) way to do that in Bubble.

So Luxon is your best bet.

With Luxon you can create a Date object in any defined timezone.

So you can take the current Date time and extract the date/month/year/hour/ minute etc (in the User’s Device Timezone), and use that to construct a new Date in any Defined Timezone.

There may be some Luxon plugins available - but it’s simple enough to just do it with some javascript directly in Bubble.

That said, I’m not sure that actually is what you’re trying to do?..

What exactly is the use-case?

Yeah I get what you’re saying, I’m likely using the wrong words. Yes, I mean I want a date object of the current time but formatted to a certain dynamic timezone. I ended up doing what you mentioned last night, I just used plugin builder and created a plugin using Luxon and it works like a charm to achieve what I want! Never knew of this library, glad to know of it now, thanks!

1 Like