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

The following examples show how to use java.util.Date#parse() . 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 File: HttpsJwks.java    From Jose4j with 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
Source File: HttpURLConnection.java    From jdk1.8-source-analysis with 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 3
Source File: TableDataMigrator.java    From quantumdb with 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 4
Source File: HttpURLConnection.java    From Bytecoder with 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 5
Source File: HttpURLConnection.java    From hottub with GNU General Public License v2.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 6
Source File: HttpURLConnection.java    From openjdk-jdk8u-backup with GNU General Public License v2.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 7
Source File: HttpURLConnection.java    From j2objc with 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 8
Source File: HttpURLConnection.java    From jdk8u-dev-jdk with GNU General Public License v2.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
Source File: HttpURLConnection.java    From jdk8u60 with GNU General Public License v2.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 10
Source File: HttpURLConnection.java    From jdk8u_jdk with GNU General Public License v2.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 11
Source File: HttpURLConnection.java    From jdk8u-jdk with GNU General Public License v2.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 File: HttpURLConnection.java    From dragonwell8_jdk with GNU General Public License v2.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 13
Source File: DotsData.java    From commcare-android with 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
Source File: URLConnection.java    From openjdk-jdk8u with GNU General Public License v2.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} 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
Source File: URLConnection.java    From openjdk-jdk8u-backup with GNU General Public License v2.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} 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
Source File: URLConnection.java    From TencentKona-8 with GNU General Public License v2.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} 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
Source File: URLConnection.java    From dragonwell8_jdk with GNU General Public License v2.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} 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
Source File: URLConnection.java    From openjdk-jdk9 with GNU General Public License v2.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} 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
Source File: URLConnection.java    From jdk-1.7-annotated with 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;
}
 
Example 20
Source File: URLConnection.java    From jdk1.8-source-analysis with 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} 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;
}