JavaScript toLocaleString function does not return left zeros

66 Views Asked by At

The problem is that the toLocaleString from Date prototype, in Spanish locale don't use 2-digit format when parsing dates with day/month only. The same problem with toLocaleDateString.

This is the problem, in Spanish locale (with en-US works fine):

const dateObj = new Date(2023, 0, 1);
console.log(dateObj.toLocaleString("es-ES", {
  day: "2-digit",
  month: "2-digit",
  year: "2-digit"
}));
// Output: 01/01/23
console.log(dateObj.toLocaleString("es-ES", {
  day: "2-digit",
  month: "2-digit"
}));
// Output: 1/1
// Expected output: 01/01

0

There are 0 best solutions below