DEV Community

Nitin Singh Solanky
Nitin Singh Solanky

Posted on

Need country current date

Hi,

I want to get IST current date time when i changed my device date time setting to any future or past date.

For example :-

  1. IST date is 12-Dec-2023
  2. I changed my device date to 10-Dec-2023.
  3. But i want to show 12-Dec-2023 in my device.

How can i do that? I already tried moment luxon.

Top comments (2)

Collapse
 
rayyannafees profile image
Rayyan Nafees • • Edited

Use the WorldTime API

U can get the JavaScript Date Object by simply:

const worldtime = await fetch("https://worldtimeapi.org/api/timezone/Asia/Kolkata")
                      .then(r=>r.json())

const date = new Date(worldtime.datetime) 
Enter fullscreen mode Exit fullscreen mode
Collapse
 
nitin41 profile image
Nitin Singh Solanky •

Thanks for your reply, but there will be possibility where my app works when no internet. And i can't store time also.