/** * Translates this calendar date to an instance of * <tt>GregorianCalendar</tt>, with the <tt>year</tt>, <tt>month</tt>, and * <tt>dayOfMonth</tt> fields set in the default time zone with the default * locale. * * @return * This calendar date as a <tt>GregorianCalendar</tt>. */ public GregorianCalendar toCalendar() { return toCalendar(new Time(0, 0, 0)); }
/** * Translates this calendar date to an instance of * <tt>GregorianCalendar</tt>, with the <tt>year</tt>, <tt>month</tt>, and * <tt>dayOfMonth</tt> fields set in the default time zone with the default * locale. * * @return * This calendar date as a <tt>GregorianCalendar</tt>. */ public GregorianCalendar toCalendar() { return toCalendar(new Time(0, 0, 0)); }
/** * Adds the specified milliseconds of days to this time and returns the * resulting time. The number of milliseconds may be negative, in which * case the result will be a time prior to this time. * * @param milliseconds * The number of milliseconds to add to this time. * * @return * The resulting time. */ public Time add(int milliseconds) { return new Time(toMilliseconds() + milliseconds); }
/** * Adds the specified milliseconds of days to this time and returns the * resulting time. The number of milliseconds may be negative, in which * case the result will be a time prior to this time. * * @param milliseconds * The number of milliseconds to add to this time. * * @return * The resulting time. */ public Time add(int milliseconds) { return new Time(toMilliseconds() + milliseconds); }
/** * Creates a new time representing the specified time string. The time * string must be in the full <tt>ISO 8601</tt> extended "time" format, * which is <tt>[hh]:[mm]:[ss]</tt>. An optional millisecond suffix of * the form <tt>.[nnn]</tt> is also supported. * * @param value * A string in the form of <tt>[hh]:[mm]:[ss]</tt> or * <tt>[hh]:[mm]:[ss].[nnn]</tt> (e.g. 17:19:20 or 17:19:20.412). */ public static Time decode(String value) { Matcher matcher = PATTERN.matcher(value); if (!matcher.matches()) { throw new IllegalArgumentException("Invalid time format: " + value); } int hour = Integer.parseInt(matcher.group(1)); int minute = Integer.parseInt(matcher.group(2)); int second = Integer.parseInt(matcher.group(3)); String millisecondSequence = matcher.group(4); int millisecond = (millisecondSequence == null) ? 0 : Integer.parseInt(millisecondSequence.substring(1)); return new Time(hour, minute, second, millisecond); } }
/** * Creates a new time representing the specified time string. The time * string must be in the full <tt>ISO 8601</tt> extended "time" format, * which is <tt>[hh]:[mm]:[ss]</tt>. An optional millisecond suffix of * the form <tt>.[nnn]</tt> is also supported. * * @param value * A string in the form of <tt>[hh]:[mm]:[ss]</tt> or * <tt>[hh]:[mm]:[ss].[nnn]</tt> (e.g. 17:19:20 or 17:19:20.412). */ public static Time decode(String value) { Matcher matcher = PATTERN.matcher(value); if (!matcher.matches()) { throw new IllegalArgumentException("Invalid time format: " + value); } int hour = Integer.parseInt(matcher.group(1)); int minute = Integer.parseInt(matcher.group(2)); int second = Integer.parseInt(matcher.group(3)); String millisecondSequence = matcher.group(4); int millisecond = (millisecondSequence == null) ? 0 : Integer.parseInt(millisecondSequence.substring(1)); return new Time(hour, minute, second, millisecond); } }