Forum Discussion
- SStalkerNew Contributor III
I do not believe there are any built in calls to get user time zone. Account Rec has each user store their local time zone in a user setting table due to this.
- RobbSalzmannValued Contributor II
The following will give you a date time group with the three letter Time Zone designation:
25/08/2023 5:00:00PM CDTDim currentDateTime As DateTime = DateTime.Now Dim formattedDateTime As String = currentDateTime.ToString("dd/MM/yyyy h:mm:ss tt") Dim regex As New Regex("\b\w") Dim tz As String = String.Concat(regex.Matches(TimeZoneInfo.Local.StandardName).Cast(Of Match)().Select(Function(m) m.Value)) return $"{formattedDateTime} {tz}"
Note: timezone information returned is based on the runtime environment of the OS server.
If you store your User's time zone ids in a table, you can use the following to get the correct date and time for their TZ:Dim targetTimeZoneId As String = "Central Standard Time" ' Replace with the desired timezone ID, e.g., "Central Standard Time" Dim targetTimeZone As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(targetTimeZoneId) Dim currentDateTime As DateTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, targetTimeZone) Dim formattedDateTime As String = currentDateTime.ToString("dd/MM/yyyy h:mm:ss tt") Dim regex As New Regex("\b\w") Dim tz As String = String.Concat(regex.Matches(targetTimeZoneId).Cast(Of Match)().Select(Function(m) m.Value)) return $"{formattedDateTime } {tz}"
- JackLacavaHonored Contributor
As others mentioned, I don't think we can know a user location, but you can look up the user Culture (there is a property on the SI object), make an assumption (i.e. if the culture is de-DE, the user will probably be in Germany) and calculate their local time accordingly.
Related Content
- 5 months ago
- 3 years ago
- 3 years ago