I want to convert the date into a system date format. For Example, if the system date format is DD-MM-YYYY, then my web application should show 30-11-2021, and on another system, if the date format is MM-DD-YYYY, then it should show 11-30-2021. Basically, it should convert to the date format of the client's system.
You can do it like this.
function formatDate(d: Date): string {
let lang: string;
if (navigator.languages != undefined) {
lang = navigator.languages[0];
} else {
lang = navigator.language;
}
const options: DateTimeFormatOptions = {
year: 'numeric',
month: '2-digit',
day: '2-digit',
};
return new Intl.DateTimeFormat(lang, options).format(d);
}