1

I am working on customizing primeng component for my requirement I came across a problem where I had to select a time and also select the time zone it should not affect the time selected but has to update the timezone as shown in the picture enter image description here

I want to update only the timezone which is GMT to UTC as per selection

is there any way to update timezone without changing the date I tried finding a solution but failed please help on the problem

NOTE: I have customized the TIMEZONE selection

Vignesh
  • 1,140
  • 1
  • 9
  • 17

2 Answers2

0

you can use toISOString() of basic JS date object (check for date docs) and then change it as you want. But I recommend you to use external library (if possible with immutable instances of datetime) even if you do not prefer to. Especially when your application will be strongly dependent on resolving multiple timezones.

0

What about setUTCHours()?

let today = new Date(Date.now());

console.log(today.toISOString());
today.setUTCHours(10);
console.log(today.toISOString());

Also using new Date(Date.UTC(year, month, day, hour, minute, second)) you can create a new date object from a specific UTC time.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC

This article can help you as well.

Bardr
  • 2,319
  • 2
  • 12
  • 21