Date format looks different on brave compared to edge and firefox

I am working on a project where i need to format the date to get the data i need and the date is formatted as 05-July. Below is the code i have to format the date:

function dateFormated() {
  return new Date()
    .toLocaleDateString("default", { day: "2-digit", month: "short" })
    .replace(" ", "-");
}

It shows incorrectly on brave July-05, but on Firefox and edge it shows the correct way i formatted 05-July.

Does anyone know the reason and how i can correct it. Appreciate your time.

I would guess (totally not sure) that Brave doesn’t provide as much information about the user (on purpose), so you don’t get to know if they are in a country that prefers day-month ordering or one that prefers month-day ordering.

It shows Jul-05 for me In Chrome as well. But in Firefox it is 05-Jul for me.

It might have to do with how the browser reads the system (OS) info. I guess the browser also has language settings that might affect it.

Try adding eng to the options.

new Date()
    .toLocaleDateString("eng", { day: "2-digit", month: "short" })
    .replace(" ", "-");

it didn’t help but i will re-implement the function. thanks

I don’t think eng, is a valid local.

Try using en-GB if you want 05-Jul

Firefox:

new Date()
    .toLocaleDateString("en-US", { day: "2-digit", month: "short" })
    .replace(" ", "-");

'Jul-05'

new Date()
    .toLocaleDateString("en-GB", { day: "2-digit", month: "short" })
    .replace(" ", "-");
	
'05-Jul'

Chrome:

new Date()
    .toLocaleDateString("en-US", { day: "2-digit", month: "short" })
    .replace(" ", "-");

'Jul-05'

new Date()
    .toLocaleDateString("en-GB", { day: "2-digit", month: "short" })
    .replace(" ", "-");
	
'05-Jul'

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.