Issue
I have an input of type date, on some computers it returns the date in the format dd/MM/yyyy, but in others it returns in the format MM/DD/yyyy, I would like it to return only format dd/MM/yyyy Brazilian pattern
<div class="input-group input-group text-center input-cep w-mmd-50 input-date">
<input formControlName="data" type="date" min="{{today}}" class="form-control"
id="inputData" >
</div>
Would there be a way to do this with just HTML or javascript or an angular pipe? I didn't find anything about it, I searched about it and it says that it changes depending on the locale or browser
Solution
The default value of date you get from input type="date" is in (yyyy-mm-dd) format you need to change that to your requirement. For reference you can check here
function myDateFormat() {
var dateControl = document.querySelector('input[type="date"]');
console.log(dateControl.value);
const [year, month, day] = dateControl.value.split('-');
const result = [day, month, year].join('/');
document.getElementById("showDate").innerHTML = result;
}
#showDate {
margin-top:10px;
}
<input type="date" onchange="myDateFormat()">
<div id="showDate"></div>
Answered By - Sumit Sharma
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.