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

455
Views
Cómo restringir las opciones de tiempo valor de hora exacto, debe restringirse después de que haya pasado el tiempo

Necesito opciones de tiempo solo 11 AM to 1 PM (1:00:00 PM only) y si la hora del sistema es 1:00:01 PM . m. tampoco debería permitirse. si el tiempo pasó después de la 1 PM p. m., necesito obtener la disponibilidad de la opción como falsa. A partir de ahora, hasta 1:59:59 PM . Si la hora de mi sistema se movió a 2 PM solo se volvió falso. Sugiérame cómo obtener la solución para esto. Debo permitir solo la 1:00:00 PM . m. y no se me debe permitir ninguna otra opción.

 public timeOptions = ['11 AM', '12 PM', '1 PM']; private currentTime: string[] = new Date() .toLocaleTimeString('en-US') .split(' '); private formattedTime: string = `${this.currentTime[0].split(':')[0]} ${ this.currentTime[1] }`; private timeIndexOnOptions: number = this.timeOptions.indexOf( this.formattedTime ); public timeOptionAvaialable(): void { let isOptionAvailable = this.timeIndexOnOptions != -1 ? true : false; console.log(isOptionAvailable);

apilar

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Parece que desea decidir si currentTime está en un intervalo. ¿Puedo entonces sugerir un enfoque alternativo? Cree un objeto de fecha que represente el comienzo del intervalo y un objeto de fecha que represente el final del intervalo y verifique si la hora actual está en ese intervalo.

 const startHours = 11; const endHours = 13; // create a Date object for 11 AM today const startTime = new Date(); startTime.setHours(startHours, 0, 0, 0); // create a Date object for 1 PM today const endTime = new Date(); endTime.setHours(endHours, 0, 0, 0); // check if current time is in the interval const currentTime = new Date(); const isOptionAvailable = currentTime > startTime && currentTime < endTime
about 4 years ago · Juan Pablo Isaza Report

0

aquí hay una pieza de código

 const timeOptions = ['11 AM', '12 PM', '1 PM']; const today = new Date().toLocaleTimeString('en-US').split(' ') const timeSplit = today[0].split(':') const index = timeOptions.indexOf(timeSplit[0] + ' ' + today[1]) // it will not wait for 1:00:00 it return false when 12:59:59 hit if (index > -1 && index !== (timeOptions.length - 1)) { console.log(true); } else { console.log(false); }

about 4 years ago · Juan Pablo Isaza Report
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!