I have a string in an ionic project that contains both a date and time, and I need to merge them into a single datetime object for sending it to the server
const date = "Fri Jan 07 2022 13:15:40 GMT+0530 (India Standard Time)";
const time = "2:15 PM";
The expected combined result would be
dateTime = 2022-01-07 14:15:00 +0530
I attempted the following code but encountered an error
'TypeError: date.replace is not a function'
const t1: any = time.split(' ');
const t2: any = t1[0].split(':');
t2[0] = t1[1] === 'PM' ? 1 * t2[0] + 12 : t2[0];
const time24 = (t2[0] < 10 ? '0' + t2[0] : t2[0]) + ':' + t2[1];
const completeDate = date.replace('00:00', time24.toString());
Can anyone assist me in obtaining the desired output
dateTime = 2022-01-07 14:15:00 +0530
using the above input strings?