Open Closed

Question on handling a certain time zone situation #6359


User avatar
0
balessi75 created

ABP Commercial 7.4.2 / Blazor Server / EF / Non tiered / Separate Host and Tenant DBs / Lepton Theme

Hi,

Our entire user base will always be located in the same time zone which is different than UTC and we would like the end user to always see their local time (East US).

We've read https://docs.abp.io/en/abp/latest/Timing and still are unsure of how to handle the following scenario...

In local development, we can convert ABP stored UTC values as pages load and everything works correctly, however this approach doesn't work when we deploy to Azure.

This is because the environments running in Azure have a local time of UTC. So we can't use CreationDateTime.ToLocalTime()as it will always return a UTC time instead of East US.

Is there anyway around this or a certain recommended approach?

Thanks in advance.


2 Answer(s)
  • User Avatar
    0
    IanW created

    Hello Baslessi75,

    You cannot use any functions which use the localtime of the machine, because when deploying to the cloud this could be different. I have personally witnessed this issue with my own projects too.

    In general the guideline is that you manage everything in UTC until it is displayed to the user. This means using Javascript to detect the users timezone in the browser https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset

    There is a Blazor library that can also take care of this for you. https://github.com/dustout/BlazorTime

  • User Avatar
    0
    balessi75 created

    Thanks for confirming IanW.

    We came up with an approach similar to what you described.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09