Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

am pm to 24 hours converter javascript

function convertTime12To24(time) {
    var hours   = Number(time.match(/^(d+)/)[1]);
    var minutes = Number(time.match(/:(d+)/)[1]);
    var AMPM    = time.match(/s(.*)$/)[1];
    if (AMPM === "PM" && hours < 12) hours = hours + 12;
    if (AMPM === "AM" && hours === 12) hours = hours - 12;
    var sHours   = hours.toString();
    var sMinutes = minutes.toString();
    if (hours < 10) sHours = "0" + sHours;
    if (minutes < 10) sMinutes = "0" + sMinutes;
    return (sHours + ":" + sMinutes);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: angular input press enter 
Javascript :: html how to remove attribute# 
Javascript :: How to find the max id in an array of objects in JavaScript 
Javascript :: node sleep 
Javascript :: jquery delete request 
Javascript :: disable eslint for react project 
Javascript :: JS get length of an object 
Javascript :: disable yellow box react native 
Javascript :: generate random date in javascript 
Javascript :: npm ERR! path node_modules/node-sass 
Javascript :: js change opacity 
Javascript :: js startswith 
Javascript :: clear ctx canvas with javascript 
Javascript :: javascript check uncheck checkbox 
Javascript :: javascript how to create an array from 1 to 100 
Javascript :: vimeo id regex 
Javascript :: remove quotes from array javascript 
Javascript :: js yesterday date 
Javascript :: npm react router dom@5 
Javascript :: firstElementChild jquery equivalent 
Javascript :: horizontal divider react native 
Javascript :: js regex valid name 
Javascript :: remove null from array javascript 
Javascript :: js check string for pangram 
Javascript :: acces vue instance from console 
Javascript :: select2 disable search 
Javascript :: js delete duplicates from array 
Javascript :: plusieurs style sur un element javascript 
Javascript :: react get url querystring 
Javascript :: blood group regex 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =