Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript conver time into 24 hour format

var dt = moment("12:15 AM", ["h:mm A"]).format("HH:mm");
Comment

convert to 24 hours format javasript

// 12:05:23AM > 00:05:23,  11:05:23AM > 23:05:23
function timeConversion(s) {
    const pad = (num)=>num.toString().padStart(2,0)
   const [hour, minutes, seconds] = s.split(':').map(parseFloat)
    return s.includes('AM')
        ? `${pad(hour % 12)}:${pad(minutes)}:${pad(seconds)}`
        : `${pad((hour  % 12) + 12 )}:${pad(minutes)}:${pad(seconds)}`;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: How to get the Class Name of an Object in JavaScript 
Javascript :: how to find last element of array react 
Javascript :: vs code shows bodyparser deprecated 
Javascript :: does filter mutate array 
Javascript :: javascript new date dd/mm/yyyy 
Javascript :: jquery addeventlistener wheel 
Javascript :: javascript two digit number 
Javascript :: how to filter out undefined keys from object in js 
Javascript :: event.preventdefault is not a function jquery 
Javascript :: bootstrap datepicker mindate and maxdate 
Javascript :: jquery map 
Javascript :: change next js default port 
Javascript :: show hidden element javascript 
Javascript :: nodejs buffer.from base64 
Javascript :: how hide .html in url 
Javascript :: axios cancel request 
Javascript :: javascript get current date format dd mm yyyy hh mm ss 
Javascript :: slice javascript string 
Javascript :: multipline and single line regex pattern 
Javascript :: remove item at index in array javascript 
Javascript :: shuffle array item javascruitp 
Javascript :: ifsc code validation formik 
Javascript :: react bootstrap carousel caption placement top 
Javascript :: difference between the `.append()` method and the `.appendChild()` method 
Javascript :: get current time jquery 
Javascript :: javascript 1 line if 
Javascript :: jquery form serialize object 
Javascript :: get element by id like javascript 
Javascript :: binarycent login 
Javascript :: get child element of parent by class 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =