I have three code. This is the first one in which I get the metadata information of any url and in that metadata I have LastModified date also. If I run this class then I ge
The best option is the third one - connection.getLastModified(), because it is the most easy-to-use method and has the highest level of abstraction. All the rest are on lower levels of abstraction: the first reads the raw response, and the second reads the raw header. The third reads the header and converts it to long.
The difference between the outputs is due to the timezone. Using new Date() you use the VM default timezone. Prefer Calendar, or best - joda-time DateTime which support custom time zones.