Date and Time Settings for NodeJS

Intro

In this tutorial we will explain the different date and time settings available for NodeJS and how to handle time zone options.

Server Time Zone

You can set the server time zone settings depending on your needs. The settings depend on if your are using Docker or not.

Using Docker

When you are using Docker, then you can adjust the server time zone settings in the target settings:

You can select UTC or your specific time zone from the list:

Not Using Docker

If you are not using Docker, in order to set your NodeJS server time zone open the Server Connect settings:

And use the Timezone option. The default time zone is OS Default, so whatever your OS is configured to. Note that this option is target specific:

You can select UTC or your specific time zone from the list. To set UTC time zone - select Etc/UTC:

Database Connection Date & Time

The date returned from your server can be formatted in a few different ways - as UTC, Server Local or the default time zone that your database driver returns.

To setup the time zone your server returns the dates in, select your database connection in Server Connect:

And you will see the Timezone Handling option:

The default value for existing projects is Driver Dependent. When this option is selected, the dates will be returned as your database driver returns them by default. This is a legacy option and we don’t recommend using it, except for your old projects which are already using it.
For new projects, the default value is UTC.

Local will return the dates in the time zone set for your server.

UTC will return the dates in UTC format in order to show the date in the user local time zone.

Select a time zone option that suits your needs and save the database connection settings:

Storing Dates in the Database

There are a couple of ways of storing the date and time in your database. Depending on your use case you can use the NOW option in Server Connect or the Date Picker component on your page.

Using Server Connect {{NOW}}

When using the NOW option in Server Connect, the date will be sent to your database in the time zone your server is. For example, you’ve set your time zone to GMT +3 and use the NOW option in the insert step:

Your date will be stored in the database in the server time zone - GMT +3

Using Date Picker

If you are using the Date Picker component, you can send the date as selected or send it as UTC. If you don’t send the date as UTC then it will be handled as if the client inserting is was located in the same time zone as your server.

If the UTC option is enabled, it will be sent to the server as UTC and properly converted to the server time zone before storing it:

Example Use Cases

One of the most frequent questions about the time zone settings is - when to use UTC and when to use a specific time zone for the server?
The answer is - it depends on your use case. It depends whether you need to show the date & time in the same regardless of the users’ time zone or do you need to show in the users’ specific time zone.

Below you can find a couple of examples of what settings do you need for specific use cases.

Example 1

Display the stored date & time to the user in the user’s time zone.
In order to display the date & time to the users in their time zone, then you need to set the:

Example 2

Display the stored date & time to the user as it is stored in the database, without converting to the users’ time zone.
In order to display the date & time to the users as it is, without converting it to their time zone, then you need to set the:

Example 3

Display the dates always in the same time zone, for example Europe/Berlin
In order to display the date & time to the users always in the Europe/Berlin time zone, then you need to set the:

As a conclusion here we can add that when using the Local option in the Database Timezone Handling settings the date & time will always be returned as stored in the database.

Community Page
Last updated: