2

I have datepicker:

    <input
        type="text"
        formControlName="startDate"
        [ngClass]="{ 'has-error': form.get('startDate').invalid }"
        [matDatepicker]="picker"
        class="materialDatePickerInput"
        placeholder="{{ 'select_date' | translate }}"
      />
      <mat-datepicker-toggle
        matSuffix
        [for]="picker"
      ></mat-datepicker-toggle>
      <mat-datepicker #picker></mat-datepicker>

I have selected date: 01.01.2000 from datepicker, but it sends to server like:

1999-12-31T20:00:00.000Z

Why it converts to wrong date?

3

1 Answer 1

2

It does not. As mentioned in the comments, it's a timezone issue. Let me explain it.

You are getting the time in the UTC format on your server side which is mostly correct. We tend to do that so that we can store time in a specific format (often in ticks) so that we can do math on it without worrying about conversion.

My guess is that your own timezone is UTC + 2. So what happens is that you choose a date, the date picker selects the day with 00 time in your own timezone and when the time is converted on your backend then 2 hours are missing.

It's not another date or the wrong one, it's just another timezone.

If you need date time then you need to decide what timezone/ locale to choose in your front end and backend.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.