2

I suffer the P-calender problem.

I choose a date (without time) from the calendar (ex. 03-09-2019) My model updates with a date object Tue Sep 03 2019 00:00:00 GMT+0530 (India Standard Time)

I send this date to the API I'm using but it works in UTC so it converts it resulting to 2019-09-02T18:30: 00.000Z.

API field is date only (no time no timezone) and it stores it as 02-09-2019 which is wrong.

Consider choosing a date from the calendar (without time) set the date in 00:00:00 in UTC time but not 00:00:00 in local time zone. Selecting a date from the browser in India Standard Time should set like 2019-09-03T18:30:00.000Z.

S.Anitha
  • 171
  • 1
  • 1
  • 7
  • Can anyone help me, for this problem – S.Anitha Sep 03 '19 at 10:42
  • if you can use momentjs, then you can simply add `const startDateUtc = moment( startDate, 'DD/MM/YY', 'Pacific/Auckland' ) .add(1, 'days') .utc() .format('YYYY-MM-DDTHH:mm');` – Ragavan Rajan Sep 04 '19 at 03:44
  • The above is just an example. Keep in mind this is one way of solving your current issue. Because you belong to different time zone. – Ragavan Rajan Sep 04 '19 at 03:48
  • tanks for your reply @Ragavan Rajan. I 'll try to solve. – S.Anitha Sep 04 '19 at 12:04
  • 1
    Answer : // fOR UTC timeZone private fixUTCDate(date): void { if (date) { date.setTime(new Date(new Date(date.getTime() - (date.getTimezoneOffset() * 60 * 1000)).toUTCString())); } } – S.Anitha Sep 04 '19 at 12:04

0 Answers0