Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

206
Visualizações
Is there an another way to get date instead of getting it from user's device

I want to make an application that will only open at a specific date. I use new date() to do that, but new date() get time from the user's device and the the user can open it by changing the time on its own device.

Example:

  let setdate = new Date('2021-12-10')
   let currentdate = new Date()
   console.log(setdate)
   if(setdate.getDate() == currentdate.getDate()){
    document.getElementById("result").style.display = 'revert'
   }
<div id=result style="display:none">Open now!!!</div>

If I don't do anything with the time of my device, it won't do anything. But if I change the date on my device to the specific date, then the area could open.

Could anyone suggests me a better way that could prevent this situation or is there an another way to get date instead of getting it from user's device

Thanks for any responds!!!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Call API, and let your frontend behaves according to its response https://worldtimeapi.org/api/timezone has good API for that.

document.body.innerHTML = '<h2>Loading ...</h2>'

fetch("https://worldtimeapi.org/api/timezone/Europe/London")
  .then(r => r.json())
  .then(data => {
    let now = new Date(data.datetime);
    myLogicPerDate(now);
   
  })
  
  
  
function myLogicPerDate(date) {

    if (date.getMinutes() % 2 ) {
       document.body.innerHTML = "You cannot see anything because it's EVEN minute"
    } else {
       document.body.innerHTML = "<h1>Welcome page</h1>You are allowed to see anything because it's ODD minute"
    
    }

}

DISCLAIMER Relying on free API is not a reliable way. So either you pay to have highest SLA from your vendor, or implement your own API & maintain its reliability.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda