不可以的,leave是一个短暂的时间的动词,不能用for two years 修饰.
应该说,
I have been away from Shanghai for two years
I have not been in Shanghai for two years.
be 呆在某地,长久时间的动词.可以.
或者,像楼上兄弟说的, It's been two years since I left Shanghai
短暂时间的动词不能用时间修饰,你不能说
I have gone to Shanghai for two years
而,I have gone to Shanghai three times 是对的.好好体会一下.