javascriptdatetime

Intl.DateTimeFormat formatted value difference between client and server


I'm currently trying to format a hour value to 12 hour format using Intl.DateTimeFormat and I noticed that if I format it on the client or on the server I get different values. If I format 12:30 (noon), on the client I get the correct value 12:30PM, but on the server I get a wrong value 0:30PM. Both formatting are done with the same function and I'm passing the same values to both.

const a = new Intl.DateTimeFormat('en-GB', {
            hour: 'numeric',
            minute: 'numeric',
            hour12: true
        })

a.format(new Date('01 Jan 1970 12:30:00'))

//on server I get 0:30PM
//on client I get 12:30PM

Solution

  • The issue seems to be related with node version I'm using (20.16.0). For some reason, even as I pass hourCycle: 'h12', node was changing it to h11. I tried updating to a newer version of node (v22.15) and the issue "fixed itself" with node not changing from h12 to h11.

    I still haven't had the time to see if it was a bug on node or something related with the implementation on that specific version of node.