Base solution for your next web application
Open Closed

Default Time Stamp Should change #921


User avatar
0
vineforce created

Hello Support,

We are facing an issue that the application is considering the UTC time zone for each activity, but we want to use the EST timezone. User can access the application is any time zone, but we want that application will use the EST timezone. Could you please help us how we can achieve this?

Thanks


10 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Please take a look at this topic Hi,

    Please take a look at this topic <a class="postlink-local" href="http://forum.aspnetboilerplate.com/viewtopic.php?f=6&t=325&p=1053&hilit=utc#p1053">viewtopic.php?f=6&t=325&p=1053&hilit=utc#p1053</a>. And this issue on ABP <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/40#issuecomment-92051308">https://github.com/aspnetboilerplate/as ... t-92051308</a>.

    Basically you need to change Clock.Provider with your implementation of IClockProvider.. And this issue on ABP <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/40#issuecomment-92051308">https://github.com/aspnetboilerplate/as ... t-92051308</a>.

    Basically you need to change Clock.Provider with your implementation of IClockProvider.

  • User Avatar
    0
    vineforce created

    How can we use the IClockProvider Interface/Clock class. As On the create event we are using the below code.

    var history = input.MapTo<TrIncentiveActivityHistory>(); await _incentiveActivityHistoryRepository.InsertAsync(history);

    The above code is saving the system's datetime for CreationTime. But I would like to change this in a specific time zone.

    Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    If your entity implements IHasCreationTime, ABP automatically sets CreationTime to Clock.Now. See SetCreationAuditProperties method here <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/a7cc09f5b1541b8543b91c6e74134a06d09c6ea7/src/Abp.EntityFramework/EntityFramework/AbpDbContext.cs">https://github.com/aspnetboilerplate/as ... Context.cs</a>.

    If you look at the Clock class in ABP(<a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/0762989fcd0493e8dc55a50a7443e891d1bffe1f/src/Abp/Timing/Clock.cs">https://github.com/aspnetboilerplate/as ... g/Clock.cs</a>), you will see

    public static DateTime Now
    {
        get { return Provider.Now; }
    }
    

    So, if you change Clock.Provider with your implementation, you can achieve what you want.

    I hope this helps.

  • User Avatar
    0
    vineforce created

    Thanks for your reply, I have a confusion how can we implement this.

    Clock.cs is placed under namespace Abp.Timing and this name space is placed under Abp.dll. In the project Abp.dll is already added then how can we change this.

    Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Just set Clock.Provider to your implementation in Global.asax or your web module's initialize method.

    Clock.Provider = new LocalClockProvider();
    
  • User Avatar
    0
    tteoh created

    If using asp.net zero template, by default, the server is running on UTC.

    Global.asax.cs is set with Clock.Provider = ClockProvders.Utc

    To use local time, the line of code to be removed according to the code comments.

    This seems to be different from the online documentation for ASP.NET ZERO, stating "... default startup solution does not enable UTC datetimes.."

    Thanks. /tommy

  • User Avatar
    0
    tteoh created

    <cite>tteoh: </cite> If using asp.net zero template, by default, the server is running on UTC.

    Global.asax.cs is set with Clock.Provider = ClockProvders.Utc

    To use local time, the line of code to be removed according to the code comments.

    This seems to be different from the online documentation for ASP.NET ZERO, stating "... default startup solution does not enable UTC datetimes.."

    Thanks. /tommy

    Correction:

    1. AspNet Zero default setting: Global.asax.cs is set with Clock.Provider = ClockProviders.Utc

    2. Remove or comment the line: System will default to ClockProvider.Unspecified

    3. To use local server time: ClockProvider.Local

    My understanding so far.

    /tommy

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @tteoh,

    Thanks for sharing your findings. Do you use AspNet Zero template ? Normally UnspecifiedClockProvider should be default in the latest version.

    Thanks.

  • User Avatar
    0
    tteoh created

    <cite>ismcagdas: </cite> Hi @tteoh,

    Thanks for sharing your findings. Do you use AspNet Zero template ? Normally UnspecifiedClockProvider should be default in the latest version.

    Thanks.

    Yes. I use AspNet Zero template. The Global.asax is set to use UTC. There is a comment states to remove the line of code if UTC is not required.

    /tommy

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @tteoh,

    Thanks for the information. It was like that in previous versions but in current version we removed it and default clock provider is Unspecified right now.