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?
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; }); }
7 Answer(s)
-
0
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:
- Set
AbpClockOptions.Kind = DateTimeKind.Utc
in all your modules (Web, API, microservices). - Use ABP's timezone conversion utilities (
IClock.ConvertToUserTime
,IClock.ConvertToUtc
) to convert between UTC and user time zone when displaying or accepting input. - Ensure your database columns are either UTC or use
timestamp with time zone
if you need to store offsets.
- Set
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.
-
0
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
-
0
[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 theTestDateTime
? If so, setting the kind toUTC
should also apply to that property.However, if you're using something like
DateTime.Now
, it uses the system's local time and ignores theKind
setting — which is exactly why we provide theIClock
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. -
0
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)
-
1
hi
Can you take a look at this article?
You need the
UseAbpTimeZone
middleware andhandleDatepicker
in javascript.https://abp.io/community/articles/developing-a-multitimezone-application-using-the-abp-framework-zk7fnrdq
-
0
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.
-
0
Great news 👍