Managing Date object time zones
Last updated
Last updated
There is a number of components that allow you to display and enter date and time values, such as Date & Time, Date picker, Date & Time picker. By default, these components use the browser time zone, i.e. the local time zone of the user to display and operate with date and time values.
Here, we talk about Date & Time, Date picker, and Date & Time picker components.
In this article, we'll explore in more details some additional options that will allow you to manage time zones in your app:
Date & Time, Date picker, and Date & Time picker components can display date and time in a specific time zone. You can achieve this by setting the component's Timezone property to the desired time zone. The time zone can be specified as a UTC offset:
Or as an IANA time zone name:
Here is an example of the Date & Time picker component that accepts the date in the user +1 hour time zone and displays it in the America/New_York time zone:
The time zone settings affect only the display of date and time. Under the hood, the Date object is always stored in the browser time zone.
By default, the Date picker and Date & Time picker components display the current date as their default values when no date is selected. You can change the default value, though, to the one you need, for example, start of month or week.
This is the current date set as the default value for a Date picker component:
Alternatively, you can set it to the start of the month:
By default, when you use Create Row or Update Row actions, the Date object is first converted to the UTC time zone and then sent to the database server. That means, that the user value entered by the user in the browser may be different from the value sent to the database.
Let's review the following example: the user selects December 10, 2024 13:00 in the Date picker, but the value sent to the database is December 10, 2024 12:00 (because of the time shift due to conversion to UTC). Now, you can prevent this behavior and send the Date object without any time zone conversion, just like it is displayed in the browser. You simply need to go to your Data source settings and select the Ignore Browser Timezone checkbox. After it's applied, you'll see that the Date is sent without conversion.
If you are using an HTTP data source, you can also send the time component of the Date object as is, but it will require some additional steps. Let's explore two ways of how you can do that:
Convert the Date object to the ISO format.
When sending the date, use the following code to convert the Date object to the ISO format with no time zone offset conversion:
After executing the action, you'll see time sent as it is displayed in the browser.
Set the UTC time zone offset to the Date picker component.
First, you need to set the component's Timezone value to +00. After that, use the following code in your action:
Setting +00 timezone on a component and using .utcOffset(0, true)
will result in an additional negative time zone offset.