I am using React DatePicker to get the date and time for a booking.
Everything seems to work, i get the right date and it gets sent to the database but if i select let's say 10:30 as time, what i get to the database is 9:30, because apparently UTC is being used but i am in UTC + 1.
I tried the following to convert to UTC + 1 but both methods didn't work. What else can i try?
First method:
const date1 = new Date()
const inc = 1000 * 60 * 60 // an hour
const _date = new Date(date1)
const [startDate, setStartDate] = useState(
new Date( _date.getTime() + inc )
);
Second method:
function addHoursToDate(date, hours) {
return new Date(new Date(date).setHours(date.getHours() + hours));
}
const myDate = new Date();
const [startDate, setStartDate] = useState(
addHoursToDate(myDate, 1 )
);