Hi,
I'm currently working with asp net boilerplate version 8.4.0 using the MVC / jQuery template.
I'm trying to display properly the CreationTime & LastModification time in my TimeZone (France). It works fine on my local computer, but as soon as I deploy the web application on Azure, It doesn't work anymore.
After reading the documentation, here are the steps I've done so far to make it work:
In the ConfigureServices method of the Startup class I added this code:
Clock.Provider = ClockProviders.Utc;
After doing this, CreationTime & LastModification are correctly saved in UTC format in the database.
I've added a derived class from SettingProvider like this, setting the time zone to "Romance Standard Time":
public class XXXXXXXXSettingProvider : SettingProvider { public override IEnumerable<SettingDefinition> GetSettingDefinitions(SettingDefinitionProviderContext context) { return new[] { new SettingDefinition( "Abp.Timing.TimeZone", "Romance Standard Time", scopes: SettingScopes.Tenant, clientVisibilityProvider: new HiddenSettingClientVisibilityProvider()) }; } }
In the Web Application module PreInitialize method I've registered the SettingProvider like this:
public override void PreInitialize() { ...
Configuration.Settings.Providers.Add<XXXXXXXXSettingProvider>(); }
To display properly the CreationTime & LastModificationTime DateTime in my time zone (France time zone) I've added this method in the ApplicationNameRazorPage.cs (base class for all the razor views)
public DateTime? LocalDateTime(DateTime? date) { return _timeZoneConverter.Convert(date, AbpSession.TenantId, AbpSession.GetUserId()); }
(_timeZoneConverter is injected via the constructor)
I'm using the LocalDateTime() method in the ViewXXXXXXXModal.cshtml & CreateOrEditModal.cshtml razor views
The CreationTime and LastModificationTime datetimes are still displaying the UTC time instead of the France time zone.
I've also the same trouble in the datatable of the index.cshtml view. I'm using the _timeZoneConverter in the DTO sent back to the browser but it still displays the UTC time format instead of the France time zone
Can you please tell me if I'm doing something wrong ? Maybe some steps are missing ? Is the "Romance Standard Time" correct name for displaying France time zone ?
A few precisions: everything seems to work properly when I set a DateTime in my local time zone with the DatePicker component (for other DateTime properties) in my User Interface. For instance, if I set 2020/06/26 09:05:00 AM --> it is correctly saved in DB as UTC format: 2020/06/26 07:05:00 AM (France is UTC + 2 hours in summer) So, the time zone set in the XXXXXXXXSettingProvider seem to work for this scenario.
Thank you very much for your help
1 Answer(s)
-
0
Hi @aldfrance
Instead of defining a custom setting provider, you can go to settings page (for host or tenant) and save the timezone setting under the General tab. After that,
LocalDateTime
should display the correct information.If it doesn't work, you can create a copy of https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp/Timing/Timezone/TimeZoneConverter.cs in your project and use it to display the DateTime values. In that way, you can debug the code and see where the problem is.