下面列出了java.util.Date#parse ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
static long getDateHeaderValue(SimpleResponse response, String headerName, long defaultValue)
{
List<String> values = getHeaderValues(response, headerName);
for (String value : values)
{
try
{
if (!value.endsWith("GMT"))
{
value += " GMT";
}
return Date.parse(value);
}
catch (Exception e)
{
// ignore it
}
}
return defaultValue;
}
@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;
}
@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;
}
@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;
}
@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;
}
@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;
}
@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;
}
@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;
}
@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;
}
@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;
}
@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;
}
private Object parseValue(Type type, String value) {
if (Strings.isNullOrEmpty(value)) {
return null;
}
switch (type) {
case SMALLINT:
case INTEGER:
return Integer.parseInt(value);
case BIGINT:
return Long.parseLong(value);
case BOOLEAN:
return Boolean.parseBoolean(value);
case TEXT:
case CHAR:
case VARCHAR:
return value;
case DATE:
return Date.parse(value);
case FLOAT:
return Float.parseFloat(value);
case TIMESTAMP:
return Timestamp.parse(value);
case OID:
return value;
case UUID:
default:
return UUID.fromString(value);
}
}
public static DotsData DeserializeDotsData(String dots) {
try {
JSONObject data = new JSONObject(new JSONTokener(dots));
Date anchor = new Date(Date.parse(data.getString("anchor")));
JSONArray jRegs = data.getJSONArray("regimens");
int[] regs = new int[jRegs.length()];
for (int i = 0; i < regs.length; ++i) {
regs[i] = jRegs.getInt(i);
}
int[][] regLabels = new int[regs.length][];
if (data.has("regimen_labels")) {
JSONArray jRegLabels = data.getJSONArray("regimen_labels");
if (jRegLabels.length() != regs.length) {
//TODO: specific exception type here
throw new RuntimeException("Invalid DOTS model! Regimens and Labels are incompatible lengths");
}
for (int i = 0; i < jRegLabels.length(); ++i) {
JSONArray jLabels = jRegLabels.getJSONArray(i);
regLabels[i] = new int[jLabels.length()];
for (int j = 0; j < jLabels.length(); ++j) {
regLabels[i][j] = jLabels.getInt(j);
}
}
} else {
//No default regimen labels
regLabels = null;
}
JSONArray jDays = data.getJSONArray("days");
DotsDay[] days = new DotsDay[jDays.length()];
for (int i = 0; i < days.length; ++i) {
days[i] = DotsDay.deserialize(jDays.getJSONArray(i));
}
return new DotsData(anchor, regs, days, regLabels);
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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</code> exists because some
* connection types (e.g., <code>http-ng</code>) 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</code> argument is returned if the field is
* missing or malformed.
*/
public long getHeaderFieldDate(String name, long Default) {
String value = getHeaderField(name);
try {
return Date.parse(value);
} catch (Exception e) { }
return Default;
}