Reputation: 13875
I have four fields that are of type Date in typescript:
StartDate
StartTime
EndDate
EndTime
I need to merge the StartDate with the StartTime into a field called Start and the EndDate with the EndTime into a field called End.
I tried doing it this way and it is not working:
start: new Date(e.startDate).setTime(e.startTime.getTime()),
end: new Date(e.endDate).setTime(e.endTime.getTime()),
Upvotes: 1
Views: 160
Reputation: 5707
Isn't this not enough?
// Prepare mock data
const startDate: Date = new Date();
const startTime: Date = new Date();
const endDate: Date = new Date();
const endTime: Date = new Date();
// Doing merge
const start: Date = new Date(startDate);
start.setHours(startTime.getHours(), startTime.getMinutes(), startTime.getSeconds(), startTime.getMilliseconds());
const end: Date = new Date(endDate);
start.setHours(endTime.getHours(), endTime.getMinutes(), endTime.getSeconds(), endTime.getMilliseconds());
Upvotes: 1