How to custom format date in jQuery/JavaScript?

by Vijay Pancholi

HTML

<!DOCTYPE html>
<html>
<body>

<h2>The Date I get from the DatePicker displays as : 17-06-2022</h2>

<p>
I need it to display as (In Danish)  : Fredag d. 17 Juni 2022
(In English) : Friday 17th June 2022</p>

<p id="demo"></p>
<p>Fredag d. 17 Juni 2022  [17-06-2022]<p/>

</body>
</html>

JavaScript

const birthday = new Date('2022 06 17');

options = {
  year: 'numeric',
  month: 'long',
  day: 'numeric',
  weekday: 'long',
};

var text = birthday.toLocaleDateString('da-DK', options);
document.getElementById("demo").innerHTML = text;