How to add 3 weeks to the_time() function

You should use get_the_time() and not the_time(). First one returns time and second one echoes it.

I don’t think you should do this in JS though (there is no need to, and users can always block JS and see this image anyway).

Your code could look something like this (it’s in PHP):

if ( strtotime( get_the_time('Y-m-d H:i:s') ) + 21*24*60*60 > time() ) {  // if post_time + 3 weeks is greater than current time
  // show your image ( the_post_thumbnail() or antyhing else you want to do)
}