This function converts time into a 12-hour format, assigns the Stack Overflow tab to the tab for this function:
Js
function ampm(date) { var hours = date.getHours(); var minutes = date.getMinutes(); var ampm = hours >= 12 ? 'pm' : 'am'; hours = hours % 12; hours = hours ? hours : 12;
HTML
<input id="time" placeholder="Time" type="time" name="time" /> > <span id="display_time"></span>
My question is how to get the value of the time input field that will be displayed on the span tag in 12hr format. This code is half working.
Displays time in 12-hour format, but displays only the current time. The flowchart will be something like: the user selects the time in the input time → some JS to convert to 12 hours format → is displayed as a 12-hour format in the span tag. Any tips or suggestions?
source share