Open Closed

Time Conversion Issue when Mvc Web Application Using Local and Other Microservices Using UTC in k8 environment with dotnet9 linux container image #9492


User avatar
0
consultant.ahmet.ulusoy created

Hi Dear Friends,

We have an issue on time convertion for time zone. When a user select a datetime from MvcUi using a calendar, it's stored as same as on UI but when we make same thing in our local environment it's working correctly. What could be reason of that?

User TimeZone Setting

AdministrationService AbpSettings TableRecord

WebModule private void ConfigureClockOptions() { Configure<AbpClockOptions>(options => { options.Kind = DateTimeKind.Local; }); }

DemoServiceModule private void ConfigureClockOptions() { Configure<AbpClockOptions>(options => { options.Kind = DateTimeKind.Utc; }); }

DemoService Details Screen

DemoService Details TableRecord


7 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    • The root cause of your time conversion issue is the inconsistent configuration of AbpClockOptions between your MVC Web Application and your microservices. In your WebModule, you have set:

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

      while in your DemoServiceModule, you have:

      Configure<AbpClockOptions>(options =>
      {
          options.Kind = DateTimeKind.Utc;
      });
      
    • This means your MVC UI is storing and interpreting DateTime values as "Local" (server time), but your microservices are using "UTC". In a distributed (microservices) environment, especially when running in containers (like Kubernetes), this will cause time drift and conversion errors, because each container/server may have a different local time or timezone configuration.

    • ABP recommends always using DateTimeKind.Utc for all services and UIs, and handling user time zone conversion at the UI or API boundary. This ensures all times are stored and transferred in UTC, and only converted to the user's time zone for display or input.

    • To fix this:

      1. Set AbpClockOptions.Kind = DateTimeKind.Utc in all your modules (Web, API, microservices).
      2. Use ABP's timezone conversion utilities (IClock.ConvertToUserTime, IClock.ConvertToUtc) to convert between UTC and user time zone when displaying or accepting input.
      3. Ensure your database columns are either UTC or use timestamp with time zone if you need to store offsets.
    • For more details and best practices, see:

      • https://abp.io/community/articles/zk7fnrdq
      • https://abp.io/docs/latest/framework/infrastructure/timing

    This approach will resolve the time drift and ensure consistent time handling across your distributed ABP application.


    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

  • User Avatar
    0
    consultant.ahmet.ulusoy created

    I tried as you describe like above in every web, api and service solution with UTC confgiuration

    Now, it's not working in my local too.

    When user select the datetime from calender, it's writing it as same as to db.

    But Abp generated fields written in UTC, user selected date time fields written as same as to db.

    For example:

    User click the today button and created the record. Creation Time saved as UTC , but Test Date Time saved as UTC+3

  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    [consultant.ahmet.ulusoy] said: User click the today button and created the record. Creation Time saved as UTC , but Test Date Time saved as UTC+3

    Hi, are you using IClock when setting the TestDateTime? If so, setting the kind to UTC should also apply to that property.

    However, if you're using something like DateTime.Now, it uses the system's local time and ignores the Kind setting — which is exactly why we provide the IClock service. It centralizes time-related operations and ensures consistency across the application.

    So, we recommend using the IClock service whenever possible to take full advantage of its benefits.

  • User Avatar
    0
    consultant.ahmet.ulusoy created

    Hi,

    Actually, user choose the date and time in a razor page view like below

    <abp-date-picker time-picker="true" auto-update-input="false" today-button-classes="btn-primary" asp-for="Detail.TestDateTime" data-date="" />
    

    And after selection, when user click the save button below method is executing.

    public virtual async Task<IActionResult> OnPostAsync()
    {
        await _detailsAppService.CreateAsync(ObjectMapper.Map<DetailCreateViewModel, DetailCreateDto>(Detail));
        return NoContent();
    }
    

    When i try to convert TestDateTime onPost method like below, it does not convert the selected time to utc. Clock.ConvertToUtc(Detail.TestDateTime.Value)

  • User Avatar
    1
    maliming created
    Support Team Fullstack Developer

    hi

    Can you take a look at this article?

    You need the UseAbpTimeZone middleware and handleDatepicker in javascript.

    https://abp.io/community/articles/developing-a-multitimezone-application-using-the-abp-framework-zk7fnrdq

  • User Avatar
    0
    consultant.ahmet.ulusoy created

    Hi ma,

    It' works now.

    Thank you so much for your suggestion, i forget to use

    $form.handleDatepicker('input[type="hidden"][data-hidden-datepicker]'); before posts.

    In the meantime, could it be more effective to develop a more global solution and prevent developers from performing the above operation on every page, and to produce a solution that will perform this operation if multi time zone is active throughout the application?

    Likewise, the same issue can be automated in data table columns where datatables are located, and if we can add a parameter to the normalizeToLocaleString() method as we passed with options when we automate it, I think it would be great.

    Thank you again for your support.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Great news 👍

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.0.0-preview. Updated on July 14, 2025, 11:57