/** * Convert a time (represented as a Date) to a String (HH:MM:SS or HH:MM:SS.SSS) * * @param d the date with the time to convert * @param includeMilliseconds controls whether milliseconds are included in the result * @return a String representing the time. */ public static String convert(Date d, boolean includeMilliseconds) { return getFormatter(includeMilliseconds).format(d); }
/** * Convert a time (represented as a Date) to a String (HH:MM:SS or HH:MM:SS.SSS) * * @param d the date with the time to convert * @param includeMilliseconds controls whether milliseconds are included in the result * @return a String representing the time. */ public static String convert(Date d, boolean includeMilliseconds) { return getFormatter(includeMilliseconds).format(d); }
/** * Convert a time (represented as a Date) to a String (HH:MM:SS or HH:MM:SS.SSS) * * @param d the date with the time to convert * @param includeMilliseconds controls whether milliseconds are included in the result * @return a String representing the time. */ public static String convert(Date d, boolean includeMilliseconds) { return getFormatter(includeMilliseconds).format(d); }
/** * Convert between a String and a time * * @param value the string to parse * @return a date object representing the time * @throws FieldConvertError raised for invalid time string */ public static Date convert(String value) throws FieldConvertError { Date d = null; if (value.length() != LENGTH_INCL_SECONDS && value.length() != LENGTH_INCL_MILLIS && value.length() != LENGTH_INCL_MICROS && value.length() != LENGTH_INCL_NANOS && value.length() != LENGTH_INCL_PICOS) { throwFieldConvertError(value, "time"); } try { final boolean includeMillis = (value.length() >= LENGTH_INCL_MILLIS); d = getFormatter(includeMillis).parse(includeMillis ? value.substring(0, LENGTH_INCL_MILLIS) : value); } catch (ParseException e) { throwFieldConvertError(value, "time"); } return d; }
/** * Convert between a String and a time * * @param value the string to parse * @return a date object representing the time * @throws FieldConvertError raised for invalid time string */ public static Date convert(String value) throws FieldConvertError { Date d = null; assertLength(value, TYPE, LENGTH_INCL_SECONDS, LENGTH_INCL_MILLIS, LENGTH_INCL_MICROS, LENGTH_INCL_NANOS, LENGTH_INCL_PICOS); try { final boolean includeMillis = (value.length() >= LENGTH_INCL_MILLIS); d = getFormatter(includeMillis).parse(includeMillis ? value.substring(0, LENGTH_INCL_MILLIS) : value); } catch (ParseException e) { throwFieldConvertError(value, TYPE); } return d; }
/** * Convert between a String and a time * * @param value the string to parse * @return a date object representing the time * @throws FieldConvertError raised for invalid time string */ public static Date convert(String value) throws FieldConvertError { Date d = null; assertLength(value, TYPE, LENGTH_INCL_SECONDS, LENGTH_INCL_MILLIS, LENGTH_INCL_MICROS, LENGTH_INCL_NANOS, LENGTH_INCL_PICOS); try { final boolean includeMillis = (value.length() >= LENGTH_INCL_MILLIS); d = getFormatter(includeMillis).parse(includeMillis ? value.substring(0, LENGTH_INCL_MILLIS) : value); } catch (ParseException e) { throwFieldConvertError(value, TYPE); } return d; }