java.net.URLConnection.getDate()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(5.7k)|赞(0)|评价(0)|浏览(339)

本文整理了Java中java.net.URLConnection.getDate()方法的一些代码示例,展示了URLConnection.getDate()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。URLConnection.getDate()方法的具体详情如下:
包路径:java.net.URLConnection
类名称:URLConnection
方法名:getDate

URLConnection.getDate介绍

[英]Returns the timestamp when this response has been sent as a date in milliseconds since January 1, 1970 GMT or 0 if this timestamp is unknown.
[中]返回自1970年1月1日GMT或0(如果此时间戳未知)以来以毫秒为单位发送此响应的时间戳。

代码示例

代码示例来源:origin: stackoverflow.com

  1. Date serverTime = new Date(connection.getDate());
  2. try {
  3. CDate = df.format(serverTime);

代码示例来源:origin: jmaki/ajax-wrapper-comp

  1. public long getDate() {
  2. if (this.urlConnection == null) return -1;
  3. return (this.urlConnection.getDate());
  4. }
  5. public String getHeader(String name) {

代码示例来源:origin: org.dihedron.commons/dihedron-commons

  1. /**
  2. * Returns the date of the response.
  3. *
  4. * @return
  5. * the date of the response.
  6. */
  7. public long getDate() {
  8. return connection.getDate();
  9. }

代码示例来源:origin: freeplane/freeplane

  1. public long getDate() {
  2. return connection.getDate();
  3. }

代码示例来源:origin: org.eclipse.jetty.osgi/jetty-osgi-boot-warurl

  1. @Override
  2. public long getDate()
  3. {
  4. return _conn.getDate();
  5. }

代码示例来源:origin: org.jboss/jboss-common-core

  1. public long getDate() {
  2. return delegateConnection.getDate();
  3. }

代码示例来源:origin: org.microemu/microemu-javase

  1. public long getDate() throws IOException {
  2. if (cn == null) {
  3. throw new IOException();
  4. }
  5. if (!connected) {
  6. cn.connect();
  7. connected = true;
  8. }
  9. return cn.getDate();
  10. }

代码示例来源:origin: org.samba.jcifs/jcifs

  1. public long getDate() {
  2. try {
  3. handshake();
  4. } catch (IOException ex) { }
  5. return connection.getDate();
  6. }

代码示例来源:origin: zyAndroid/countdown

  1. @Override
  2. protected Long doInBackground(Long... longs) {
  3. URL url = null;//取得资源对象
  4. try {
  5. url = new URL("http://www.bjtime.cn");
  6. URLConnection uc = url.openConnection();
  7. uc.connect();
  8. time_net = uc.getDate();
  9. if (time_net < longs[0]) {
  10. return longs[0] - time_net;
  11. } else {
  12. return (long) 0;
  13. }
  14. } catch (Exception e) {
  15. Log.d("countdown", "Exception: " + e);
  16. }
  17. return (long) 0;
  18. }

代码示例来源:origin: knightliao/common-utils

  1. /**
  2. * 获取远程服务器日期
  3. *
  4. * @param url 链接地址
  5. *
  6. * <p>
  7. * http://192.9.162.55
  8. * <p>
  9. * http://java.sun.com
  10. * </p>
  11. * @return 远程服务器日期,如果反生异常,返回当前日期
  12. */
  13. public static Date getRemoteDate(String url) {
  14. if (url == null) {
  15. return null;
  16. }
  17. URLConnection uc;
  18. try {
  19. uc = new URL(url).openConnection();
  20. uc.connect(); // 发出连接
  21. return new Date(uc.getDate());// 生成连接对象
  22. } catch (IOException e) {
  23. return new Date();
  24. }
  25. }

代码示例来源:origin: apache/cxf

  1. /**
  2. * Finds the timestamp for a given URI. Calls {@link #getBaseFileURI(URI)} prior to the timestamp
  3. * check in order to handle "classpath" and "jar" URIs.
  4. *
  5. * @param uri the URI to timestamp
  6. * @return a timestamp
  7. */
  8. protected long getTimestamp(URI uri) {
  9. long timestamp = 0;
  10. URI baseURI = getBaseFileURI(uri);
  11. if ("file".equals(baseURI.getScheme())) {
  12. timestamp = new File(baseURI).lastModified();
  13. } else {
  14. try {
  15. timestamp = baseURI.toURL().openConnection().getDate();
  16. } catch (Exception e) {
  17. // ignore
  18. }
  19. }
  20. return timestamp;
  21. }

代码示例来源:origin: org.glassfish.external/schema2beans

  1. private static long getLastModified(Class cls) {
  2. try {
  3. String shortName = cls.getName().substring(1+cls.getName().lastIndexOf('.'));
  4. java.net.URL url = cls.getResource(shortName + ".class");
  5. String file = url.getFile();
  6. //System.out.println("url="+url);
  7. if ("file".equals(url.getProtocol())) {
  8. // example: file='/home/cliffwd/cvs/dublin/nb_all/schema2beans/rt/src/org/netbeans/modules/schema2beans/GenBeans.class'
  9. String result = file.substring(0, file.length() - cls.getName().length() - 6);
  10. return new File(file).lastModified();
  11. } else if ("jar".equals(url.getProtocol())) {
  12. // example: file = 'jar:/usr/local/j2sdkee1.3.1/lib/j2ee.jar!/org/w3c/dom/Node.class'
  13. String jarFile = file.substring(file.indexOf(':')+1);
  14. jarFile = jarFile.substring(0, jarFile.indexOf('!'));
  15. //System.out.println("jarFile="+jarFile);
  16. return new File(jarFile).lastModified();
  17. }
  18. return url.openConnection().getDate();
  19. } catch (java.io.IOException e) {
  20. return 0;
  21. }
  22. }
  23. }

代码示例来源:origin: org.apache.cxf/cxf-codegen-plugin

  1. /**
  2. * Finds the timestamp for a given URI. Calls {@link #getBaseFileURI(URI)} prior to the timestamp
  3. * check in order to handle "classpath" and "jar" URIs.
  4. *
  5. * @param uri the URI to timestamp
  6. * @return a timestamp
  7. */
  8. protected long getTimestamp(URI uri) {
  9. long timestamp = 0;
  10. URI baseURI = getBaseFileURI(uri);
  11. if ("file".equals(baseURI.getScheme())) {
  12. timestamp = new File(baseURI).lastModified();
  13. } else {
  14. try {
  15. timestamp = baseURI.toURL().openConnection().getDate();
  16. } catch (Exception e) {
  17. // ignore
  18. }
  19. }
  20. return timestamp;
  21. }

代码示例来源:origin: apache/cxf

  1. } else {
  2. try {
  3. timestamp = wsdlURI.toURL().openConnection().getDate();
  4. } catch (Exception e) {

代码示例来源:origin: apache/cxf

  1. } else {
  2. try {
  3. timestamp = wadlURI.toURL().openConnection().getDate();
  4. } catch (Exception e) {

代码示例来源:origin: org.apache.cxf/cxf-codegen-plugin

  1. } else {
  2. try {
  3. timestamp = wsdlURI.toURL().openConnection().getDate();
  4. } catch (Exception e) {

代码示例来源:origin: stackoverflow.com

  1. http = (HttpURLConnection) url.openConnection();
  2. Log.i("getDate", "="+http.getDate());
  3. http.connect();
  4. result = convertStreamToString((InputStream)http.getContent());

代码示例来源:origin: com.github.houbie/rhino-mod

  1. final long response_time = System.currentTimeMillis();
  2. final long apparent_age = Math.max(0, response_time -
  3. urlConnection.getDate());
  4. final long corrected_received_age = Math.max(apparent_age,
  5. urlConnection.getHeaderFieldInt("Age", 0) * 1000L);

代码示例来源:origin: io.apigee/rhino

  1. final long response_time = System.currentTimeMillis();
  2. final long apparent_age = Math.max(0, response_time -
  3. urlConnection.getDate());
  4. final long corrected_received_age = Math.max(apparent_age,
  5. urlConnection.getHeaderFieldInt("Age", 0) * 1000L);

代码示例来源:origin: octo-online/reactive-audit

  1. @Test(expected = NetworkReactiveAuditException.class)
  2. public void getDate()
  3. throws IOException
  4. {
  5. Assume.assumeTrue(IOTestTools.isNetworkConnected());
  6. ReactiveAudit.off.commit();
  7. URLConnection conn = new URL("http://" + HOST + ":" + PORT).openConnection();
  8. TestTools.strict.commit();
  9. conn.getDate();
  10. }

相关文章

URLConnection类方法