How to change default date format in JavaScript or in HTML

137
March 04, 2022, at 12:40 PM

I've a input field as type date and the of that format is dd/mm/yyyy which is not default. In my desktop screen it's working properly and also I've a placeholder in the same field as DD/MM/YYYY.

All is working fine in desktop screen but once I change screen from desktop to iPads or mobile devices my placeholder isn't working and date format automatically changed to mm/dd/yyyy.

Is there any solution available for the date format so that it remains same in desktop screens and iPad or mobile screen.

Answer 1

Below is an example of parsing an input field of type date.

No matter what locale your using, if it's DD/MM/YYYY or MM/DD/YYYY or even YYYY-DD-MM if that even exists, it will always create the correct search string.

const input = document.querySelector('input');
const r = document.querySelector('span');
function updateSearch() {
  if (input.value) {
    r.innerText = input.value.split('-').reverse().join('/');
  } else r.innterText = '';
}
input.addEventListener('change', updateSearch);
updateSearch();
<input type="date"/><br/><br/>
Search will be -> <span></span>

Rent Charter Buses Company
READ ALSO
How to adjust Bulma Column height when one changes?

How to adjust Bulma Column height when one changes?

is it possible to make a column adjust its height when others change? I have all columns at the same height using flex but when I change one of them dynamically, the others stay the same

119
how to override user agent stylesheet in fullscreen on mobile?

how to override user agent stylesheet in fullscreen on mobile?

I'm working on mobile version of http://library-devbdrc

170
Javascript onclick event out of phase in Angular

Javascript onclick event out of phase in Angular

Using Angular framework to build my website's front-end, I'm trying to include a button/icon capable of opening and closing this sidenav:

122
CSS: new font breaking layout by aligning text to the top

CSS: new font breaking layout by aligning text to the top

I've been working with Open Sans in a project for a while and we then decided to use a new font, and after adding the new font the layout breaks everywhere and the text appears to be aligned to the topHere are some screenshots for a simple text in an icon:

113