Hi @Paulo_dev1 -
The problem you're encountering is that the .toLocaleDateString
method formats the date based on the local settings of the machine running the code, rather than the locale specified in the argument. To ensure that you get the desired format, you may need to pass in additional options to the method.
I have made a couple of tests to have the date formatted as "dd/mm/yyyy".
Here's an example of how you can achieve the same:
var options = {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
hour12: false,
timeZone: 'Europe/London',
};
var date = new Date();
var formattedDate = date.toLocaleDateString('en-GB', options);
The options object in the above example sets the format for the date string, including the length of the day and month, the use of a 12-hour or 24-hour clock, and the time zone.
Note that the support for time zones in JavaScript is limited, and may not provide full coverage for all regions. You can also refer to the MDN web docs for more information and alternative methods.