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

DateTime in database and client #4862


User avatar
0
mika created

Hi

I try to get DateTime from client, send it to database and then edit same datetime. I use the demo datetimepicker and get the date and post it to backend.

Here are the post parameters: post_parameters.PNG eventDate is the datetime object and i wrote on eventText what I set on datetimepicker. So here, I set the time to 8:30 (GMT +2) and eventDate shows that date in UTC format. Everything ok.

These values are saved to database and model is full auditet entity so there is also creation time: database.PNG

There EventDate is saved as UTC format.

Question 1:

  • <ins>Why CreationTime is not UTC?</ins> I made the post 8.30 on local time (GMT+2).

Now I Get the date and here is result from backend: get_response.PNG

Again event date is UTC, but there is nothing to clarify that this is UTC time? Question 2:

  • What I should do at client end to set it as UTC time?

This is the input field I use.

<input class="form-control" #EditEventTimeInput name="EditEventTimeInput"
                               type="datetime" formControlName="eventDate">

Form creation, input initial value set.

eventDate: this.originalHistory.eventDate.format('L LT'),

after this form initialization, I set the datetime locale and format as demo site shows

$(this.eventTime.nativeElement).datetimepicker({
            locale: abp.localization.currentLanguage.name,
            format: 'L LT'
        });

Now when date is set on input it shows 03/16/2018 6:30 AM, so it shows UTC format, or it is not converted to local time.

Angular & Core


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

    Hi @Mika,

    If you want ABP framework to convert dates to UTC and save them into database as UTC, you need to set "Clock.Provider = ClockProviders.Utc" in your Startup.cs.

    Otherwise, ABP framework will not be touching your dates at all. If you use ClockProviders.Utc, then each user can change their timezone settings on the "My Settings" dialog.

    By the way, as you know, it is not possible to store timezone information on a datetime field on the database.