0

I need in jQuery/Javascript to display a date (comming from a DatePicker) with more information and depending on language:

The Date I get from the DatePicker displays as : 17-06-2022

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

My code:

$( document ).ready(function() {
  $('#BtnProceed').click(function() {
        var date = document.getElementById("ConfirmEndDateHolder").value = EndCalendar.getFormatedDate();
        $("#ConfirmEndDateHolder").text(date);
  });    
});

Can someone help me achive this?

Stig Kølbæk
  • 432
  • 2
  • 18
  • You would need to manually build date strings in those formats. There are libraries which can help you with this, such as [MomentJs](https://momentjs.com/), although you would need to build the logic to differentiate the user's language/culture yourself. – Rory McCrossan Jun 17 '22 at 09:31
  • [.toLocaleDateString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString) eg `date.toLocaleString('da-DK', {weekday: 'long'});` – freedomn-m Jun 17 '22 at 09:37
  • There are also lots of [SO questions](https://stackoverflow.com/search?q=%5Bjavascript%5D+detect+user+language) on how to detect user's language. – freedomn-m Jun 17 '22 at 09:43
  • Thanks Guys .. I think I might need to look into the moment.js then .. I am not able to get `$("#ConfirmEndDateHolder").text(date.toLocaleString('da-DK', {weekday: 'long'}));` to display other than i.e. 17-06-2022 .. maybe I am doing something wrong? – Stig Kølbæk Jun 17 '22 at 10:14

0 Answers0