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

201
Views
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 answers
Answer question

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 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!