Base solution for your next web application
Open Closed

Problem displaying DateTime for France TimeZone #9267


User avatar
0
aldfrance created

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:

  1. 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.

  2. 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()) }; } }

  3. In the Web Application module PreInitialize method I've registered the SettingProvider like this:

    public override void PreInitialize() { ...

         Configuration.Settings.Providers.Add&lt;XXXXXXXXSettingProvider&gt;();
     }
    
  4. 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)
    
  5. 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)