Timezone change

I just want to change the default timezone to New Yorks timezone but I do not know how am I supposed to do that!
strapi Version - 3.3.4
Node Version - 10.19.0
database - Mongodb

Was there a specific reason for this as it’s generally considered a bad practice to change the database timezone. Typically backends should function in a common “Universal” time zone (luckily UTC exists) thus most DBAs strongly frown upon changing the server/database timezone and generally expect the client side to do this as they are the single “source of truth” as to what the time zone is.

The client is generally responsible for accepting the UTC value and converting it to the users time zone on READ and for CREATE/UPDATE converting the users time back to UTC before sending.

Agree with @DMehaffy - best to db timestamp in UTC+0 time.

I had to deal with timezones in my own app, and here’s some snippets I used to convert to the right timezones:

In my controller for posts in my Strapi app, using the SQL function AT TIME ZONE:

...strapi.connections.default.raw(`SELECT p.author, p.published_at AT TIME ZONE t.timezone) FROM posts p `);

I used Nuxt.js as frontend so I also use the native Javascript function Intl.DateTimeFormat() to format dates based on user’s browser timezone:

formatDate: (dateStr, string) =>
      Intl.DateTimeFormat('en-GB', {
        year: 'numeric',
        month: 'short',
        day: 'numeric',
        hour: 'numeric',
        minute: 'numeric',
        hourCycle: 'h12',
        // hour12: true, // gives weird 00:11 pm for 12:11noontime
        timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
      }).format(new Date(dateStr)),
1 Like