Java URL Connection getRemoteTimestamp(final String url)

Here you can find the source of getRemoteTimestamp(final String url)

Description

get Remote Timestamp

License

Open Source License

Parameter

Parameter Description
url - The url of the resource we want to get its timestamp.

Return

The timestamp (last modification date) of the specified url/resource, -1L if an error occurred, 0L if not known.

Declaration

public static long getRemoteTimestamp(final String url) 

Method Source Code

//package com.java2s;
/*/*from  w  ww  .j  a va 2 s . co  m*/
 * This file is part of WaqtSalat-Service.
 * 
 * WaqtSalat-Service is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * WaqtSalat-Service is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with WaqtSalat-Service. If not, see <http://www.gnu.org/licenses/>.
 */

import java.net.URL;
import java.net.URLConnection;

public class Main {
    /**
     * @param url
     *            - The url of the resource we want to get its timestamp.
     * @return The timestamp (last modification date) of the specified
     *         url/resource, -1L if an error occurred, 0L if not known.
     */
    public static long getRemoteTimestamp(final String url) {
        try {
            URL u = new URL(url);
            URLConnection urlc = u.openConnection();
            return urlc.getLastModified();

        } catch (Exception e) {
            return -1L;
        }
    }
}

Related

  1. getOutputStream(final URL outputURL)
  2. getOutputStream(URL url)
  3. getPage(String url)
  4. getPageContent(String inputUrlString)
  5. getRealURL(URL url)
  6. getRequest(URLConnection conn)
  7. getRequestHeaders(URLConnection conn)
  8. getResultsWithEncoding(URLConnection source, String encoding)
  9. getStream(URL url)