André Vieira wrote:
Your data below is not working. . FYI
"(UTC+05:00) Qyzylorda"
"(UTC+04:00) Volgograd"
Hi gents,
I reckon Andre's proposed solution is a good one. I'm located at Australia. And By selecting the respective time zone and hit search, BOOM!, I got the identifier of my time zone, which is exactly the attribute for the action - ConvertTimeFromUTC(currentTime, TimeZone).
In terms of foramtting the time, I would suggest using DateTime_PrettyFormat(..). Very Handy.
Hello Andre,
how would it be in case that I have many users entering from different timezones? and How can I change the time format from YYYYMMDD HH:MM:SS to MMDDYYYY HH:MM AM/PM ?
Thanks
HI Alvaro,
You should store your dates in UTC and convert them to the timezone of each user for display only. The way you manage this can be by automatically determining the timezone from the browser or the device or by a user configuration in the backoffice. Either way, you need to program for this.
Regarding the format it is independent of the timezone conversion since the timezone returns a DateTime. You can use the FormatDateTime function for that.
Cheers
Hello
Function (GetCurrentTimeZone) does get the system time zone from the server. Any idea how to get the client time zone? Will it be the client time zone defined on the PC or derived from another parameter like the IP?
Khalil Dahham wrote:
The client time will be derived based on the Client Browser settings for the Locale of the client,
Thank you André for sharing the test page, it was very helpful. Just one question about Daylight Saving, as you know the date to change the clocks for daylight saving might be different between countries, for example Mexico changes to daylight savings one or two weeks after the US, does TimeZone takes into account the dates defined by each country, or how does it works?
Hi Isa,
The information about daylight saving is handled by the underlying library in .NET or Java. The library reports if the timezone supports daylight saving time and if it is currently using daylight saving time. You can test this on the test page searching for "Mexico, Mexico" in the location input.
What am I missing? I still don't understand how to get the client's timezone rather than the server's timezone.
Hi Peter.
Unfortunately the client timezone is not available through this component. Heck, it isn't even available through HTTP (as opposed to the language, which is available in HTTP headers).
You need to resort to JavaScript to find out the client's timezone. Here is the API you should use for that effect: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset
What I suggest you to do is to use this JavaScript API to send the offset to the server, and store it on a session variable. You can do this by including a hidden input and a button on your layout web block, then on page load use a javascript to write the timezone offset into that input and automatically click the button. Make sure the button is an ajax submit. I also suggest you only do this once (e.g. skip the click on the button if the session variable was already initialized with an offset).
A consequence of this is that you cannot be sure of the client's timezone on the first page load. If you need to re-render some content, you can end the button's logic with a redirect, which will reload the screen. A better usability would be to display a message saying "we detected that your timezone is XXX, click here to update the app to this timezone", and only set the session variable if the user clicks that link. The advantage of this is that it handles users that are in transit or on a short trip, and intentionally don't want to use the current timezone.
Hi Peter,
Check this article for a step by step instructions how to work with time zones.
Regards,
Marcelo
Thanks Leonardo & Marcelo!
the sample site doesn't seem to work anymore, how do you get the timezone for New York, i keep getting XXX timezone not found in local computer.
I tried
"America/New_York"
"EST"
One of the functions in there will give you the list of timezones available to you on your environment.
J.Ja