Java Code Examples for java.util.Date.parse()

The following are Jave code examples for showing how to use parse() of the java.util.Date class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: truevfs   File: HttpNode.java   View Source Code Vote up 5 votes
@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;
}
 
Example 2
Project: lams   File: ServletWebRequest.java   View Source Code Vote up 5 votes
@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;
}
 
Example 3
Project: OpenJSharp   File: HttpURLConnection.java   View Source Code Vote up 5 votes
@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;
}
 
Example 4
Project: Simpler   File: NumberFormatter.java   View Source Code Vote up 5 votes
/**
 * 转换时间
 *
 * @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");
    }
}
 
Example 5
Project: jdk8u-jdk   File: HttpURLConnection.java   View Source Code Vote up 5 votes
@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;
}
 
Example 6
Project: openjdk-jdk10   File: HttpURLConnection.java   View Source Code Vote up 5 votes
@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;
}
 
Example 7
Project: school-express-delivery   File: Test.java   View Source Code Vote up 4 votes
public static Date parse(String date) {
    /**The time format like "Mon Aug 01 17:04:17 +0800 2016" */
    return new Date(Date.parse(date));
}
 
Example 8
Project: OpenJSharp   File: URLConnection.java   View Source Code Vote up 3 votes
/**
 * 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;
}
 
Example 9
Project: jdk8u-jdk   File: URLConnection.java   View Source Code Vote up 3 votes
/**
 * 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;
}
 
Example 10
Project: openjdk-jdk10   File: URLConnection.java   View Source Code Vote up 3 votes
/**
 * 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;
}