As I understand that the ASP.NET Zero backend stores date fields such as CreationTime, LastModificationTime, etc., in UTC format, which makes sense for consistency across time zones.
However, I'm currently facing an issue on the frontend where these UTC dates are displayed directly to the user, without being converted to the user's local time zone. As a result, users in different time zones see incorrect dates/times.
What is the recommended way within ASP.NET Zero to handle date/time localization on the frontend so that these values are properly converted to the user’s local time zone before display?
Thanks in advance!
7 Answer(s)
-
0
Hi @benjamin.edinger
If the Time Zone feature is enabled in your application, UTC+0 is considered the default. In this case, values such as
CreationTimeandLastModificationTimeare stored in the database based on UTC+0. Once this feature is enabled, you can update the time zone from the Host Settings page if you wish to change the default. However, if the Time Zone feature is not enabled which is the default behavior records are created based on the application's local time. Is the issue you're describing occurring in a specific area only?Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi @oguzhanagir, Not not in a specific area. Could you please show me what configuration I need to change because I can't find it under Host Settings.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi @benjamin.edinger
As stated in this document, you need to add the code snippet below into
PreInitializeinCoreModule.Clock.Provider = ClockProviders.Utc;Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi @oguzhanagir, What if the user inputs a date on a model entity on the frontend. Then on the backend this is converted to UTC date and saved in the database. But dates which the user set manually must never change to UTC. It has to stay in the users time zone.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi @benjamin.edinger
In Angular, date and time conversions are handled on the client side based on UTC. You can refer to the
setDatemethod defined in theAbpDateTimePickerComponentto see how this process is implemented. This method processes the date either based on UTC or a specified time zone, and then sends it to the backend accordingly.If needed, you can remove these controls and implement custom date and time handling logic based on your specific scenario. However, the current approach is designed to ensure consistency across the application, particularly in cases where users manually input date and time values.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi @oguzhanagir,
I came across the
[DisableDateTimeNormalization]attribute and wanted to confirm its suitability for our needs. Our goal is to ensure that when a user enters a date on the frontend—such as a document date used for accounting—the value remains exactly the same across all time zones. This consistency is crucial for maintaining accurate accounting records.Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi @benjamin.edinger
Yes, the
[DisableDateTimeNormalization]attribute can be used in your scenario. However, it is important to ensure that the date entered by the user on the frontend is retrieved from the backend, not the default date set by theAbpDateTimePickerComponentin Angular. You can refer to the example usage of the[DisableDateTimeNormalization]attribute in the Boilerplate documentation: Disable DateTime Normalization.The AbpDateTimePickerComponent is utilized in Angular pages when creating an entity with a DateTime property in Power Tools.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)