org.apache.shindig.common.util.DateUtil类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(216)

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

DateUtil介绍

[英]Date parsing and writing utilities.
[中]日期解析和写入实用程序。

代码示例

代码示例来源:origin: org.apache.shindig/shindig-common

/**
 * Formats an RFC 1123 format date.
 */
public static String formatRfc1123Date(Date date) {
 return formatRfc1123Date(date.getTime());
}

代码示例来源:origin: org.gatein.shindig/shindig-gadgets

/**
 * @return the expiration time from the Expires header or -1 if not set
 */
private long getExpiresTime() {
 String expires = getHeader("Expires");
 if (expires != null) {
  Date expiresDate = DateUtil.parseRfc1123Date(expires);
  if (expiresDate != null) {
   return expiresDate.getTime();
  } else {
   // Per RFC2616, 14.21 (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.21):
   // "HTTP/1.1 clients and caches MUST treat other invalid date formats,
   // especially including the value "0", as in the past (i.e., "already
   // expired")."
   return 0;
  }
 }
 return -1;
}

代码示例来源:origin: com.lmco.shindig/shindig-common

/**
 * Formats an ISO 8601 format date.
 */
public static String formatIso8601Date(Date date) {
  return formatIso8601Date(date.getTime());
}

代码示例来源:origin: org.apache.shindig/shindig-gadgets

/**
 * Tries to find a valid date from the input headers.
 *
 * @return The value of the date header, in milliseconds, or -1 if no Date could be determined.
 */
private static long getAndUpdateDate(Multimap<String, String> headers) {
 // Validate the Date header. Must conform to the HTTP date format.
 long timestamp = -1;
 long currentTime = getTimeSource().currentTimeMillis();
 Collection<String> dates = headers.get(HttpHeaders.DATE);
 if (!dates.isEmpty()) {
  Date d = DateUtil.parseRfc1123Date(dates.iterator().next());
  if (d != null) {
   timestamp = d.getTime();
  }
 }
 if (timestamp == -1) {
  timestamp = currentTime;
  headers.replaceValues(HttpHeaders.DATE, ImmutableList.of(DateUtil.formatRfc1123Date(timestamp)));
 }
 return timestamp;
}

代码示例来源:origin: org.gatein.shindig/shindig-common

@Test
public void parseMalformedIso8691() {
  assertNull(DateUtil.parseIso8601DateTime("invalid date format"));
}

代码示例来源:origin: com.lmco.shindig/shindig-gadgets

/**
 * Tries to find a valid date from the input headers.
 *
 * @return The value of the date header, in milliseconds, or -1 if no Date could be determined.
 */
private static long getAndUpdateDate(Multimap<String, String> headers) {
 // Validate the Date header. Must conform to the HTTP date format.
 long timestamp = -1;
 long currentTime = getTimeSource().currentTimeMillis();
 Collection<String> dates = headers.get("Date");
 if (!dates.isEmpty()) {
  Date d = DateUtil.parseRfc1123Date(dates.iterator().next());
  if (d != null) {
   timestamp = d.getTime();
   if (Math.abs(currentTime - timestamp) > responseDateDriftLimit) {
    // Do not trust the date from response if it is too old (server time out of sync)
    timestamp = -1;
   }
  }
 }
 if (timestamp == -1) {
  timestamp = currentTime;
  headers.replaceValues("Date", ImmutableList.of(DateUtil.formatRfc1123Date(timestamp)));
 }
 return timestamp;
}

代码示例来源:origin: org.apache.shindig/shindig-common

@Test
public void parseMalformedIso8691() {
  assertNull(DateUtil.parseIso8601DateTime("invalid date format"));
}

代码示例来源:origin: com.lmco.shindig/shindig-common

/**
 * Formats an RFC 1123 format date.
 */
public static String formatRfc1123Date(Date date) {
 return formatRfc1123Date(date.getTime());
}

代码示例来源:origin: com.lmco.shindig/shindig-gadgets

/**
 * @return the expiration time from the Expires header or -1 if not set
 */
private long getExpiresTime() {
 String expires = getHeader("Expires");
 if (expires != null) {
  Date expiresDate = DateUtil.parseRfc1123Date(expires);
  if (expiresDate != null) {
   return expiresDate.getTime();
  } else {
   // Per RFC2616, 14.21 (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.21):
   // "HTTP/1.1 clients and caches MUST treat other invalid date formats,
   // especially including the value "0", as in the past (i.e., "already
   // expired")."
   return 0;
  }
 }
 return -1;
}

代码示例来源:origin: org.wso2.org.apache.shindig/shindig-common

/**
 * Formats an ISO 8601 format date.
 */
public static String formatIso8601Date(Date date) {
  return formatIso8601Date(date.getTime());
}

代码示例来源:origin: org.wso2.org.apache.shindig/shindig-common

@Test
public void parseMalformedIso8691() {
  assertNull(DateUtil.parseIso8601DateTime("invalid date format"));
}

代码示例来源:origin: org.gatein.shindig/shindig-common

/**
 * Formats an RFC 1123 format date.
 */
public static String formatRfc1123Date(Date date) {
 return formatRfc1123Date(date.getTime());
}

代码示例来源:origin: org.apache.shindig/shindig-gadgets

/**
 * @return the expiration time from the Expires header or -1 if not set
 */
public long getExpiresTime() {
 String expires = getHeader(HttpHeaders.EXPIRES);
 if (expires != null) {
  Date expiresDate = DateUtil.parseRfc1123Date(expires);
  if (expiresDate != null) {
   return expiresDate.getTime();
  } else {
   // Per RFC2616, 14.21 (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.21):
   // "HTTP/1.1 clients and caches MUST treat other invalid date formats,
   // especially including the value "0", as in the past (i.e., "already
   // expired")."
   return 0;
  }
 }
 return -1;
}

代码示例来源:origin: org.gatein.shindig/shindig-common

/**
 * Formats an ISO 8601 format date.
 */
public static String formatIso8601Date(Date date) {
  return formatIso8601Date(date.getTime());
}

代码示例来源:origin: com.lmco.shindig/shindig-common

@Test
public void parseMalformedIso8691() {
  assertNull(DateUtil.parseIso8601DateTime("invalid date format"));
}

代码示例来源:origin: org.wso2.org.apache.shindig/shindig-common

/**
 * Formats an RFC 1123 format date.
 */
public static String formatRfc1123Date(Date date) {
 return formatRfc1123Date(date.getTime());
}

代码示例来源:origin: org.apache.shindig/shindig-common

@Test
public void parse() {
 for (int i = 0, j = rfc1123text.length; i < j; ++i) {
  assertEquals(timeStamps[i].getTime(), DateUtil.parseRfc1123Date(rfc1123text[i]).getTime());
 }
}

代码示例来源:origin: org.apache.shindig/shindig-common

/**
 * Formats an ISO 8601 format date.
 */
public static String formatIso8601Date(Date date) {
  return formatIso8601Date(date.getTime());
}

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

@Test
public void parseMalformedIso8691() {
  assertNull(DateUtil.parseIso8601DateTime("invalid date format"));
}

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

/**
 * Formats an RFC 1123 format date.
 */
public static String formatRfc1123Date(Date date) {
 return formatRfc1123Date(date.getTime());
}

相关文章