Base solution for your next web application
Open Closed

User Timezones and UTC ClockProvider #3799


User avatar
0
blewis created

I have users across the United States and I need to display UTC dates that are stored in the DB in the user's local time. I understand all of the concepts of converting UTC times to local time within ASP.Net, but not within the ABP framework.

I am using the Asp.Net CORE MVC & jQuery project. Where should I be setting the clock provider to Utc? Startup.cs? After the provider is set, all I need to do is create a Abp.Timing.TimeZone setting for the tenant and/or user and my DB results from Entity Framework will be auto converted to the local timezone?

Thanks, Bryan


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @blewis,

    All is correct just one thing:

    my DB results from Entity Framework will be auto converted to the local timezone

    Your date values will be in UTC when you retrieve them on the client side. You need to use user's timezone setting to convert/display given UTC date to user.

    We have used momentjs and moment-timezone libraries to do that. Please let us know if you need help on this.

    Thanks.

  • User Avatar
    0
    blewis created

    While I am doing some stuff server-side (not with Moment), I figured it out. However, I think you have a typo in your docs. On the page about Timing at <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Timing#DocTimeZones">https://aspnetboilerplate.com/Pages/Doc ... cTimeZones</a>, you state:

    ABP assumes that value of timezone setting is a valid Windows timezone id.

    When I attempted to use the numeric Windows Timezone ID as documented by MS at <a class="postlink" href="https://msdn.microsoft.com/en-us/library/gg154758.aspx">https://msdn.microsoft.com/en-us/library/gg154758.aspx</a>, it starting giving me errors. When I changed the Abp.Timing.TimeZone setting to the Timezone Name (e.g. "Pacific Standard Time") everything was fine.

    Bryan

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @blewis,

    Thanks for the information, yes it should be Timezone Name instead of Id, we will fix it.