Base solution for your next web application
Open Closed

How to show/read all dates from DB in specific time zone? #2737


User avatar
0
pradippatil created

Hi,

We store all the dates in UTC format. What will be the best way to read/show all dates from DB in a specific time zone. Does ABP template provides this facility using Clock, if yes, how to use it?

Thanks


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

    Hi,

    In AspNet Zero, we handled it in this way.

    1. We return the values in UTC to client.
    2. We use <a class="postlink" href="https://momentjs.com/timezone/">https://momentjs.com/timezone/</a> library and set the timezone with user's current timezone setting. You can reach it using "abp.timing.timeZoneInfo.iana.timeZoneId" on the client side.
    3. Then you can use momentjs to format your dates and it will show dates in the specific time zone.

    Please write back if you have a different requirement.

    Thanks.

  • User Avatar
    0
    tteoh created

    <cite>ismcagdas: </cite> Hi,

    In AspNet Zero, we handled it in this way.

    1. We return the values in UTC to client.
    2. We use <a class="postlink" href="https://momentjs.com/timezone/">https://momentjs.com/timezone/</a> library and set the timezone with user's current timezone setting. You can reach it using "abp.timing.timeZoneInfo.iana.timeZoneId" on the client side.
    3. Then you can use momentjs to format your dates and it will show dates in the specific time zone.

    Please write back if you have a different requirement.

    Thanks.

    Hi Ismail,

    Even the default implemented Clock.Provider is set to "Local"? AspNet Zero will first convert the date/time stored in DB in Local to UTC before returning the data to Client side?

    Thanks. p/s: Sincere apology if i got your name wrong.

  • User Avatar
    0
    tteoh created

    <cite>tteoh: </cite>

    <cite>ismcagdas: </cite> Hi,

    In AspNet Zero, we handled it in this way.

    1. We return the values in UTC to client.
    2. We use <a class="postlink" href="https://momentjs.com/timezone/">https://momentjs.com/timezone/</a> library and set the timezone with user's current timezone setting. You can reach it using "abp.timing.timeZoneInfo.iana.timeZoneId" on the client side.
    3. Then you can use momentjs to format your dates and it will show dates in the specific time zone.

    Please write back if you have a different requirement.

    Thanks.

    Hi Ismail,

    Even the default implemented Clock.Provider is set to "Local"? AspNet Zero will first convert the date/time stored in DB in Local to UTC before returning the data to Client side?

    Thanks. p/s: Sincere apology if i got your name wrong.

    Hi,

    With reference to question above, i believe the answer is "No". Correct?

    After spending my weekends to step through the program in debug mode and writing to console.log in browser, my understanding is below:

    1. At Application_Start, by setting Clock.Provider = ClockProviders.local OR remove existing setting to UTC, the appliction will run with Unspecified provider. This also means the system is not running with Multiple Timezone: [Yes | No]?
    2. Inherently, the Timezone setting for Application and Users are disabled [Yes | No]?
    3. Abp will save date/time value as-is from browser to database and vice versa [Yes | No]?

    Thanks. /Tommy

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    With reference to question above, i believe the answer is "No". Correct?

    Yes, the answer is no :).

    1. At Application_Start, by setting Clock.Provider = ClockProviders.local OR remove existing setting to UTC, the appliction will run with Unspecified provider. This also means the system is not running with Multiple Timezone: [Yes | No]?

    Yes, correct.

    1. Inherently, the Timezone setting for Application and Users are disabled [Yes | No]?

    Yes, exactly.

    1. Abp will save date/time value as-is from browser to database and vice versa [Yes | No]?

    Yes, but there is a slight difference here. When you use UnspecifiedClockProvider, ABP does not do any operation on the date values send from client to server and vice versa, but .NET Framework does.

    Also when you use LocalClockProvider, all dates will be converted to local timezone. For example when you send an UTC date string from client to server, it will be converted to server's local timezone.

    Thanks.