本文整理匯總了Java中java.util.Date.parse方法的典型用法代碼示例。如果您正苦於以下問題:Java Date.parse方法的具體用法?Java Date.parse怎麽用?Java Date.parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Date
的用法示例。
在下文中一共展示了Date.parse方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getTime
import java.util.Date; //導入方法依賴的package包/類
@Override
@SuppressWarnings("deprecation")
public long getTime(Access type) {
if (WRITE != type)
return UNKNOWN;
try {
final String field = getHeaderField("last-modified");
if (null != field)
return Date.parse(field);
} catch (IllegalArgumentException | IOException ex) {
}
return UNKNOWN;
}
示例2: checkNotModified
import java.util.Date; //導入方法依賴的package包/類
@Override
@SuppressWarnings("deprecation")
public boolean checkNotModified(long lastModifiedTimestamp) {
if (lastModifiedTimestamp >= 0 && !this.notModified &&
(this.response == null || !this.response.containsHeader(HEADER_LAST_MODIFIED))) {
long ifModifiedSince = -1;
try {
ifModifiedSince = getRequest().getDateHeader(HEADER_IF_MODIFIED_SINCE);
}
catch (IllegalArgumentException ex) {
String headerValue = getRequest().getHeader(HEADER_IF_MODIFIED_SINCE);
// Possibly an IE 10 style value: "Wed, 09 Apr 2014 09:57:42 GMT; length=13774"
int separatorIndex = headerValue.indexOf(';');
if (separatorIndex != -1) {
String datePart = headerValue.substring(0, separatorIndex);
try {
ifModifiedSince = Date.parse(datePart);
}
catch (IllegalArgumentException ex2) {
// Giving up
}
}
}
this.notModified = (ifModifiedSince >= (lastModifiedTimestamp / 1000 * 1000));
if (this.response != null) {
if (this.notModified && supportsNotModifiedStatus()) {
this.response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
}
else {
this.response.setDateHeader(HEADER_LAST_MODIFIED, lastModifiedTimestamp);
}
}
}
return this.notModified;
}
示例3: getHeaderFieldDate
import java.util.Date; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
public long getHeaderFieldDate(String name, long Default) {
String dateString = getHeaderField(name);
try {
if (dateString.indexOf("GMT") == -1) {
dateString = dateString+" GMT";
}
return Date.parse(dateString);
} catch (Exception e) {
}
return Default;
}
示例4: dateTransfer
import java.util.Date; //導入方法依賴的package包/類
/**
* 轉換時間
*
* @param now -1:直接格式化為yyyy-MM-dd HH:mm:ss <br />
* 當前毫秒數:格式化為微博格式 <br />
* @param time
* @return
*/
public static String dateTransfer(long now, String time) {
long createAtTime = Date.parse(time);
Date createAt = new Date(createAtTime);
if (now != -1) {
long second = (now - createAtTime) / 1000L;
if (second < 0) {
second = 0;
}
if (second == 0) {
return "剛剛";
} else if (second < 30) {
return second + "秒以前";
} else if (second < 60) {
return "半分鍾前";
} else if (second < 60 * 60) {
return (second / 60) + "分鍾前";
} else if (second <= 60 * 60 * 3) {
return (second / 60 / 60) + "小時前";
} else if (getFormatTime(createAt, "d").equals(Calendar.getInstance().get(Calendar.DATE) + "")) {
return "今天 " + getFormatTime(createAt, "HH:mm");
} else if (getFormatTime(createAt, "d").equals((Calendar.getInstance().get(Calendar.DATE) - 1) + "")) {
return "昨天 " + getFormatTime(createAt, "HH:mm");
} else if (second < 60 * 60 * 24 * 7) {
return (((second / 60) / 60) / 24) + "天前";
} else if (getFormatTime(createAt, "yyyy").equals(Calendar.getInstance().get(Calendar.YEAR) + "")) {
// 同一年
return getFormatTime(createAt, "MM-dd HH:mm");
}
return getFormatTime(createAt, "yyyy-MM-dd HH:mm");
} else {
return getFormatTime(createAt, "yyyy-MM-dd HH:mm:ss");
}
}
示例5: parse
import java.util.Date; //導入方法依賴的package包/類
public static Date parse(String date) {
/**The time format like "Mon Aug 01 17:04:17 +0800 2016" */
return new Date(Date.parse(date));
}
示例6: getHeaderFieldDate
import java.util.Date; //導入方法依賴的package包/類
/**
* Returns the value of the named field parsed as date.
* The result is the number of milliseconds since January 1, 1970 GMT
* represented by the named field.
* <p>
* This form of {@code getHeaderField} exists because some
* connection types (e.g., {@code http-ng}) have pre-parsed
* headers. Classes for that connection type can override this method
* and short-circuit the parsing.
*
* @param name the name of the header field.
* @param Default a default value.
* @return the value of the field, parsed as a date. The value of the
* {@code Default} argument is returned if the field is
* missing or malformed.
*/
@SuppressWarnings("deprecation")
public long getHeaderFieldDate(String name, long Default) {
String value = getHeaderField(name);
try {
return Date.parse(value);
} catch (Exception e) { }
return Default;
}