Get the Last Modified date of an URL

前端 未结 3 1105
心在旅途
心在旅途 2020-12-15 05:08

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

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-15 05:35

    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.

提交回复
热议问题