Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

How does Abp get the current time zone? #3651


User avatar
0
soonjoo created

Hello, may I know how does Abp get current time zone? I am asking because for my own created entity, it shows 8 hour slower than my time zone, while the entity that asp zero create is 3 hour slower than my time zone... this is when I'm checking the database. My time zone is +8 gmt.

Thank you


6 Answer(s)
  • User Avatar
    0
    alper created
    Support Team

    hi,

    there's doc about timezone <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Timing">https://aspnetboilerplate.com/Pages/Documents/Timing</a>

  • User Avatar
    0
    soonjoo created

    Hello, may I know specifically where to set the timezone? I read in the docs

    You can set Clock.Provider in order to use a different clock provider: Clock.Provider = ClockProviders.Utc; This is generally done at the beginning of an application (proper to do it Application_Start in a web application).

    however, I still do not know exactly where to set it. I want the time to be consistent throughout the application, so it always saves as UTC time in the database.

    I am using .net core and angular. Thanks.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @soonjoo,

    You can do it in Startup.cs of your project.

    Thanks.

  • User Avatar
    0
    soonjoo created

    is it correct I do it here in the constructor of startup.cs?

    public class Startup
        {
            private const string DefaultCorsPolicyName = "localhost";
    
            private readonly IConfigurationRoot _appConfiguration;
    
            public Startup(IHostingEnvironment env)
            {
                _appConfiguration = env.GetAppConfiguration();
                Clock.Provider = ClockProviders.Utc;
            }
            ...
            ...
            ...
        }
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @soonjoo,

    Yes you can do it like this, but we prefer to do it in ConfigureServices method.

  • User Avatar
    0
    BigCDogCrew created

    @ismcagdas,

    We have used DateTime.UtcNow to populate all of our custom datetime fields. But the ABP fields (CreationTime, DeletionTime, LastModificationTime) all use local time. Our current work-around is to run our Azure servers in UTC, which assures that all DateTime fields are stored in UTC. But it's time to make a proper fix.

    We are using AspNetZero v8.4, Abp 5.5, Mvc/jQuery.

    Will you please provide an example of how to change the clock provider in ConfigureServices?

    Based upon earlier posts in this thread, it looks like we should go back and replace all "DateTime.UtcNow" references with "ClockProviders.Utc.Now". Do you advise that change?

    Thanks, BigC