Get current timezone with Xojo Cloud

Hello. I would like to get the user’s current timezone, but when I deploy to Xojo Cloud, it seems to be reverting to the default GMT timezone. Tried the following

dim d as DateTime = DateTime.Now
dim d as DateTime = DateTime.Now(TimeZone.Current)
dim d as DateTime = DateTime.Now(New TimeZone(TimeZone.Current)) 'this one give an error

The first two work in debug but show the GMT when deployed to XC

Also tried this but still showing GMT

dim d as DateTime = DateTime.Now(New TimeZone(TimeZone.Current.Abbreviation))

You should use WebSession - ClientTime: WebSession — Xojo documentation

The code you posted shows the server time. In debug mode your server is your local computer.

Thanks Alberto, but I must still be doing something wrong. The following still show GMT

dim d as DateTime = Session.ClientTime.Now
dim d as DateTime = Session.ClientTime.Now(New TimeZone(TimeZone.Current.Abbreviation))
dim d as DateTime = Session.ClientTime.Now(New TimeZone(Session.ClientTime.Timezone.Current.Abbreviation))
dim d as DateTime = DateTime.Now(New TimeZone(Session.ClientTime.Timezone.Current.Abbreviation))

Try only Session.ClientTime
don’t use .Now

dim d as DateTime = Session.ClientTime
1 Like

Wonderful! That did the trick. Thanks for the help today!