Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript format hour

function timeConversion(s) {
  const formatter = s.replace(/[a-z]/gi, '').split(':')
  let firstIndex = +formatter[0]
  let time = 12
  let time1 = ""
  let time2 = ""
 
  for(let i = 0; i < formatter.length; i++) {
      
       if(i == 0 && firstIndex < 12) {
         time += +formatter[0]
         time1 += String(time)
       }
    
       if(i == 0 && firstIndex > 11) {
         time -= +formatter[0]
         time1 += String(Math.abs(time)).repeat(2)
       }
      
       if(i !== 0) {
         time2 += " " + formatter[i]
       }
  }

 return time1.concat(time2).replace(/[s]/g, ':')
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: read data from store i ngrxstore 
Javascript :: how to change selected link in jquery 
Javascript :: paypal react native 
Javascript :: find document which is not in array 
Javascript :: alpine: Cannot reference "$wire" outside a Livewire component. 
Javascript :: Date.now beautiful human readable 
Javascript :: convert componentWillUnmount into useEffect 
Javascript :: odata filter query error Property access can only be applied to a single value. 
Javascript :: const is avaiable for es version 6 
Javascript :: How to set variable data in JSON body for the code that generated by Postman in c# 
Javascript :: remove or add class jquery 
Javascript :: function return string javascript 
Javascript :: how to slice one specific element from array in angular 
Javascript :: Collision between two div vanillaJS no detection 
Javascript :: disable button without losing value 
Javascript :: acender lampada javascript 
Javascript :: pagination component 
Javascript :: React Native - Trigger Media Scanner 
Javascript :: javascript pdf 
Javascript :: angular refresh component on button click 
Javascript :: import js with vite ts 
Javascript :: how to create a snake game in html css js 
Javascript :: javascript check if valid url 
Javascript :: react native password field 
Javascript :: jeebisah 
Javascript :: The slice reducer for key "books" returned undefined during initia 
Javascript :: firebase messaging service not working with electron 
Javascript :: Tableau JS api getdata 
Javascript :: Simple Email Validation, Case Insensitive, w/ All Valid Local Part Characters (whatever tf that means to you...) - Regex 
Javascript :: javascript one line if without else 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =