08-25-2023 09:51 AM
08-25-2023 01:10 PM
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.
08-25-2023 06:25 PM - edited 08-25-2023 06:55 PM
The following will give you a date time group with the three letter Time Zone designation:
25/08/2023 5:00:00PM CDT
Dim 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}"
08-26-2023 04:23 AM
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.