Open Closed

DateTime not converted into correct timezone #2211


User avatar
0
morindo created

Greetings, we are currently investigatin ABP Commercial v.5.0.0-rc1 with Blazor Server and we are trying to understand the Timing documentation. We have configured our appsettings.json and added Abp.Timing.Timezone settings into the AbpSettings table and configured the AbpClockOptions Kind option to DateTimeKind.Utc into the Blazor project but all the DateTime values in the UI are always in UTC.

Do we need to configure anything else for the DateTime to show in the correct timezone?

Thank you,

project.DatePosted = Clock.Now;

appsettings.json

"Settings": {
    "Volo.Abp.LeptonTheme.Style": "Style6", /* Options: Style1, Style2... Style6 */
    "Volo.Abp.LeptonTheme.Layout.MenuPlacement": "Left", /* Options: Left, Top */
    "Volo.Abp.LeptonTheme.Layout.MenuStatus": "AlwaysOpened", /* Options: AlwaysOpened, OpenOnHover */
    "Volo.Abp.LeptonTheme.Layout.Boxed": "False", /* Options: True, False */
    "Abp.Timing.Timezone": "America/Montreal"
  }

AbpSettings table

| Id | Name | Value | ProviderName | ProviderKey | | --- | ---- | ----- | ------------ | ----------- | | a00efa60-cd8e-4b8c-9fb1-b9eeff5e930c | Abp.Timing.Timezone | America/Montreal | U | 766fa024-a7a7-c009-5601-3a0079bb60d2 | | 4a78b825-59c8-472a-b425-e54174cb225e | Abp.Timing.Timezone | America/Montreal | G | NULL |

{ProjectName}BlazorModule.cs

public override void ConfigureServices(ServiceConfigurationContext context)
        {
            var hostingEnvironment = context.Services.GetHostingEnvironment();
            var configuration = context.Services.GetConfiguration();

            Configure<AbpClockOptions>(options =>
            {
                options.Kind = DateTimeKind.Utc;
            });

            ConfigureUrls(configuration);
            ConfigureBundles();
            ConfigureAuthentication(context, configuration);
            ConfigureImpersonation(context, configuration);
            ConfigureAutoMapper();
            ConfigureVirtualFileSystem(hostingEnvironment);
            ConfigureLocalizationServices();
            ConfigureSwaggerServices(context.Services);
            ConfigureExternalProviders(context, configuration);
            ConfigureAutoApiControllers();
            ConfigureBlazorise(context);
            ConfigureRouter(context);
            ConfigureMenu(context);
            ConfigureLeptonTheme();
        }
  • ABP Framework version: v5.0.0-rc1
  • UI type: Blazor Server
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no / no
  • Exception message and stack trace: No exception
  • Steps to reproduce the issue: Create a new project using abp suite. Generate an entity with a DateTime.

1 Answer(s)
  • User Avatar
    0
    cotur created

    Hello @morindo

    ABP is not converting the DateTimes automatically for the client timezone.

    You need to manually convert it for your clients. Let me show you what I did;

    I just add the following configuration to my BlazorModule.

    Configure<AbpClockOptions>(options =>
                {
                    options.Kind = DateTimeKind.Utc;
                });
    
    

    With this configuration, ABP Framework will use only UTC time. It will saves the utc datatimes to DB also. Saving datetime as UTC is best-practise.

    But, users may be located in different timezones, and I need to manually convert some "dateTime" properties as following.

    Here is the result for website: (my local time is not UTC)

    Here is the Database record:

    As you can see, time is 09:26:34 at DB but I am successfuly converting it to my local time at the blazor client.

    For user defined inputs, you do not need to convert to UTC, ABP automatically converts the inputs to UTC time (because we configured below)

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