Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
Input time html, validate not allow more than 59 react handle change

I can type different number for minutes like 99, how can I validate this, I need it to be when I start typing 99 to make 09. this is on react

const [datetime, setDatetime] = useState<number>(post.id ? post.datetime : newDate.getTime() || new Date().getTime())

const dateReal = new Date()
  let hour = dateReal.getHours()
  let minutes = dateReal.getMinutes()
  if (hour > 12) {
    hour = hour - 12
  }
  if (minutes < 10) {
    minutes = `0${parseInt(minutes)}`
  }
  if (hour < 10) {
    hour = `0${parseInt(hour)}`
  }

  const [hours, setHours] = useState(hour)
  const [newMinutes, setMinutes] = useState(minutes)

  const newFullDate = format(new Date(datetime), 'eeee dd,  MMM - ') + hours + ' : ' + newMinutes

  function getTime (datetime: number) {
    return post.id ? format(new Date(datetime), 'HH:mm') : hours + ':' + newMinutes
  }


  const handleTimeChange = (event) => {
    const time = event.target.value
 
    if (time) {
      const newDatetime = format(new Date(datetime), 'yyyy-MM-dd\'T\'') + time
      const timeConverted = new Date(newDatetime).getTime()
      const newTime = time.split(':')
      const hour = newTime[0]
      const min = newTime[1]
      setHours(hour)
     
   
      setMinutes(min)



      setDatetime(timeConverted)
    }
  }
  
  
  
       <input
              className={styles.timer}
              type='time'
              name='appt-time'
              onChange={handleTimeChange}
              value={getTime(datetime)}
            />

I am showing a part of code before return the logic, and after that I have put my input time, I know on html input time does not allow to do 99 it automatically makes it 09, I don't know why here with handle it is messing up

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!