user3301207
user3301207

Reputation: 3

Convert 24 hr format to 12 hr format using javascript

i m using html5 time attribute ; like this

<input type="time" class="inputDateFromTo" id="time"  />

it is showing time in 24 hrs format ; but i want it in 12 hrs format with am/pm, ex "4.30 PM"

please suggest me the code using simple javascript or pattern attribute

Upvotes: 0

Views: 214

Answers (2)

Paul S.
Paul S.

Reputation: 66394

You can make one yourself using something like the following

<input type="text" required placeholder="hh:mm" pattern="\d\d?:\d\d" />
<select>
    <option selected value="am">AM</option>
    <option value="pm">PM</option>
</select>

Upvotes: 0

Krish R
Krish R

Reputation: 22741

You can use input type as type="datetime-local"

 <input type="datetime-local" class="inputDateFromTo" id="time">

Upvotes: 1

Related Questions