I have two date variable separately like following
startDate is a Date instance with the value Tue Jul 17 2012 00:00:00 GMT+0530 (IST)
startTime is a String with the value "11:30 AM"
Now what I need is join of both above date & time, as a Date.
startDateTime = Tue Jul 17 2012 11:30:00 GMT+0530 (IST)
I tried
new Date(startDate + " " + startDate) but outputting invalid date.
Also tried the way shown on this post. But still not working.
You can readily parse
startTimeif it’s in a clearly-defined format, then usesetHoursandsetMinutes: Live example | source…or something along those lines.
Note that key to this is the fact you’ve said
startDateis aDateinstance. The above assumes we’re working within the timezone of the JavaScript environment, not across zones. If you were starting with a date string instead, and that string specified a timezone other than the JavaScript environment’s timezone, which you were then converting into aDatevianew Date("Tues Jul...."), then you’d have to be sure to adjust the resultingDateto use either the local time of the environment, or UTC; if you adjusted it to be UTC, you’d usesetUTCHoursandsetUTCSecondsabove instead ofsetHoursandsetSeconds. Again, this is only an issue if your starting point is a date string, and that string specifies a timezone different from the timezone in which the code above is running.