Issue
I am currently facing an issue in JS where I need to enforce a 24-hour format in each time input but, in MAC only it is showing a 12-hour format. I could not find useful solutions, most of them suggested using a date-picker package but that I don't want to do. Is there any possible solution to this problem?
Here is my code
const dateTimeString = (timestamp) => {
return new Date(timestamp).toISOString().substring(0, 16);
};
function createElement({
type,
attributes = {},
innerText
}) {
const element = document.createElement(type);
Object.keys(attributes).forEach((item) => {
element.setAttribute(item, attributes[item]);
});
element.textContent = innerText;
return element;
}
const extensionForContainer = document.getElementById("extension-container")
const extensionInput = createElement({
type: 'input',
attributes: {
class: 'date-input hidden',
type: 'datetime-local',
name: 'newEndsOn',
id: 'newEndsOn',
value: dateTimeString(1698196920),
},
});
extensionForContainer.appendChild(extensionInput);
<html>
<div id="extension-container">
</div>
</html>
Solution
It depends upon the system preferences, you cannot enforce it.
Answered By - Amit
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.