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

The following examples show how to use java.util.Date#parse() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Jose4j   File: HttpsJwks.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
@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 3
@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
@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 5
@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
@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
@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 8
Source Project: j2objc   File: HttpURLConnection.java    License: Apache License 2.0 5 votes vote down vote up
@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 9
@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 10
@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 11
Source Project: Bytecoder   File: HttpURLConnection.java    License: Apache License 2.0 5 votes vote down vote up
@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 12
Source Project: quantumdb   File: TableDataMigrator.java    License: Apache License 2.0 5 votes vote down vote up
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);
	}
}
 
Example 13
Source Project: commcare-android   File: DotsData.java    License: Apache License 2.0 4 votes vote down vote up
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);
        }


    }
 
Example 14
/**
 * 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 15
/**
 * 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 16
/**
 * 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 17
/**
 * 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 18
/**
 * 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 19
/**
 * 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 20
Source Project: jdk-1.7-annotated   File: URLConnection.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * 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;
}