/** * Convert the given number of milliseconds to a human-readable string * @param millis the milliseconds * @return the string */ public static String format(long millis) { String r = FORMATTER.format(Duration.ofMillis(millis)); if (r.isEmpty()) { return "0s"; } return r.trim(); }
? (from + 8 == to) : (from + 7 == to)); Duration<?> dur = getAlternativeDateFormat(extended, ordinalStyle).parse(period, from); long years = dur.getPartialAmount(YEARS); long months; extended = (period.charAt(from + 2) == ':'); Duration<?> dur = getAlternativeTimeFormat(extended).parse(period, from); long hours = dur.getPartialAmount(HOURS); if (hours > 0) {
) { return new Formatter<>(type, pattern);
/** * <p>Creates a textual output of given temporal amount and writes to * the buffer. </p> * * @param threeten temporal amount * @param buffer I/O-buffer where the result is written to * @throws IllegalArgumentException if some aspects of temporal amount * prevents printing (for example mixed signs) * @throws IOException if writing into buffer fails * @see Duration#from(TemporalAmount) * @since 4.0 */ /*[deutsch] * <p>Erzeugt eine textuelle Ausgabe des angegebenen Zeitbetrags und * schreibt sie in den Puffer. </p> * * @param threeten temporal amount * @param buffer I/O-buffer where the result is written to * @throws IllegalArgumentException if some aspects of temporal amount * prevents printing (for example mixed signs) * @throws IOException if writing into buffer fails * @see Duration#from(TemporalAmount) * @since 4.0 */ public void print( TemporalAmount threeten, Appendable buffer ) throws IOException { this.print(Duration.from(threeten), buffer); }
/** * <p>Handles Joda-Time-style-patterns which in general follow XML-schema * - with the exception of sign handling. </p> * * <p>The sign handling of Joda-Time allows and even enforces in contrast * to XML-schema negative signs not before the P-symbol but for every * single duration item repeatedly. Warning: Mixed signs are never supported * by Time4J. </p> * * @return new formatter instance for parsing Joda-Style period expressions * @since 3.0 * @see #ofPattern(Class, String) */ /*[deutsch] * <p>Behandelt Joda-Time-Stil-Formatmuster, die im allgemeinen XML-Schema * folgen - mit der Ausnahme der Vorzeichenbehandlung. </p> * * <p>Die Vorzeichenbehandlung von Joda-Time erlaubt und erzwingt im Kontrast * zu XML-Schema negative Vorzeichen nicht vor dem P-Symbol, sondern wiederholt * für jedes einzelne Dauerelement. Warnung: Gemischte Vorzeichen werden * von Time4J dennoch nicht unterstützt. </p> * * @return new formatter instance for parsing Joda-Style period expressions * @since 3.0 * @see #ofPattern(Class, String) */ public static Formatter<IsoUnit> ofJodaStyle() { return ofPattern(IsoUnit.class, JODA_PATTERN); }
/** * <p>Equivalent to {@link net.time4j.Duration.Formatter#ofPattern(Class, String)}. </p> * * @param <U> generic unit type * @param type reified unit type * @param pattern format pattern * @return new formatter instance * @throws IllegalArgumentException in any case of pattern inconsistencies or failures * @since 3.0 */ /*[deutsch] * <p>Äquivalent zu {@link net.time4j.Duration.Formatter#ofPattern(Class, String)}. </p> * * @param <U> generic unit type * @param type reified unit type * @param pattern format pattern * @return new formatter instance * @throws IllegalArgumentException in any case of pattern inconsistencies or failures * @since 3.0 */ public static <U extends IsoUnit> Duration.Formatter<U> formatter( Class<U> type, String pattern ) { return Duration.Formatter.ofPattern(type, pattern); }
/** * <p>Creates a textual output of given temporal amount. </p> * * @param threeten temporal amount * @return textual representation of duration * @throws IllegalArgumentException if some aspects of temporal amount * prevents printing (for example mixed signs) * @see Duration#from(TemporalAmount) * @since 4.0 */ /*[deutsch] * <p>Erzeugt eine textuelle Ausgabe des angegebenen Zeitbetrags. </p> * * @param threeten temporal amount * @return textual representation of duration * @throws IllegalArgumentException if some aspects of temporal amount * prevents printing (for example mixed signs) * @see Duration#from(TemporalAmount) * @since 4.0 */ public String format(TemporalAmount threeten) { return this.format(Duration.from(threeten)); }
/** * <p>Equivalent to {@link net.time4j.Duration.Formatter#ofPattern(String)}. </p> * * @param pattern format pattern * @return new formatter instance * @throws IllegalArgumentException in any case of pattern inconsistencies or failures * @since 3.0 */ /*[deutsch] * <p>Äquivalent zu {@link net.time4j.Duration.Formatter#ofPattern(String)}. </p> * * @param pattern format pattern * @return new formatter instance * @throws IllegalArgumentException in any case of pattern inconsistencies or failures * @since 3.0 */ public static Duration.Formatter<IsoUnit> formatter(String pattern) { return Duration.Formatter.ofPattern(pattern); }
/** * <p>Equivalent to {@code ofPattern(IsoUnit.class, pattern)}. </p> * * @param pattern format pattern * @return new formatter instance * @throws IllegalArgumentException in any case of pattern inconsistencies or failures * @since 1.2 * @see #ofPattern(Class, String) */ /*[deutsch] * <p>Äquivalent zu {@code ofPattern(IsoUnit.class, pattern)}. </p> * * @param pattern format pattern * @return new formatter instance * @throws IllegalArgumentException in any case of pattern inconsistencies or failures * @since 1.2 * @see #ofPattern(Class, String) */ public static Formatter<IsoUnit> ofPattern(String pattern) { return ofPattern(IsoUnit.class, pattern); }
private static Duration.Formatter<CalendarUnit> createAlternativeDateFormat( boolean extended, boolean ordinalStyle ) { String pattern; if (extended) { if (ordinalStyle) { pattern = "YYYY-DDD"; } else { pattern = "YYYY-MM-DD"; } } else { if (ordinalStyle) { pattern = "YYYYDDD"; } else { pattern = "YYYYMMDD"; } } return Duration.Formatter.ofPattern(CalendarUnit.class, pattern); }
private static Duration.Formatter<ClockUnit> createAlternativeTimeFormat(boolean extended) { String pattern = ( extended ? "hh[:mm[:ss[,fffffffff]]]" : "hh[mm[ss[,fffffffff]]]" ); return Duration.Formatter.ofPattern(ClockUnit.class, pattern); }