2

I am trying to get the user's timezone time. not the time set by the user locally. because that will cause many problems in my app.

I tried:-

    var date = new Date()
    var offsetInMin = date.getTimezoneOffset()

But it just shows the difference between the local time zone and the UTC.

Is there a way to get the timezone's(for me Kolkata) time rather than the local time of the device?

I found some APIs but it would be better to do it without APIs..

sanket kheni
  • 1,482
  • 2
  • 12
  • 29
  • you could use UTC time zone – sairaj Aug 31 '21 at 06:02
  • 1
    It's unclear to me what you mean - particularly when you're asking about "the globe timezone's time" after first saying you want "the user's timezone time". Please clarify your question. – Jon Skeet Aug 31 '21 at 06:05
  • 1
    What do you mean by "timezone time"? The exact time that would be returned by an 'ntp' service? Then you have to request such a service. Or the time in a fixed timezone, regardless of what timezone the user has set? Then it's probably better to work in UTC time, as this is independent from any timezones – derpirscher Aug 31 '21 at 06:15
  • yes. the time that is the default one, when the time is set to use automatically in device settings. not time set by the user. some users change their system time.. – sanket kheni Aug 31 '21 at 06:17
  • If you don't trust the local device's time to be accurate, then you cannot use the local clock at all. It's not like the local device has some hidden "accurate" setting somewhere. If its time is set wrong, then it cannot give you the correct time by definition. You'd need to fetch the time from a trusted, accurate server, also accounting for the network delay, at which point you're into NTP territory. – deceze Aug 31 '21 at 06:18
  • Yeah thanks. is there any free time servers?? – sanket kheni Aug 31 '21 at 06:19
  • 1
    Thousands. Have a look at https://pool.ntp.org – derpirscher Aug 31 '21 at 06:22

0 Answers0