Joda-Time. , , , , , , , 2.5.
Period period = new Period(new LocalDate(2013, 4, 11), LocalDate.now());
PeriodFormatter formatter = PeriodFormat.wordBased(Locale.GERMANY);
System.out.println(formatter.print(period));
formatter = formatter.withLocale(Locale.ENGLISH);
System.out.println(formatter.print(period));
formatter = PeriodFormat.wordBased(Locale.ENGLISH);
System.out.println(formatter.print(period));
, . -- , ( ):
PeriodFormat.space=\
PeriodFormat.comma=,
PeriodFormat.commandand=,and
PeriodFormat.commaspaceand=, and
PeriodFormat.commaspace=,
PeriodFormat.spaceandspace=\ and
PeriodFormat.year=\ year
PeriodFormat.years=\ years
PeriodFormat.month=\ month
PeriodFormat.months=\ months
PeriodFormat.week=\ week
PeriodFormat.weeks=\ weeks
PeriodFormat.day=\ day
PeriodFormat.days=\ days
PeriodFormat.hour=\ hour
PeriodFormat.hours=\ hours
PeriodFormat.minute=\ minute
PeriodFormat.minutes=\ minutes
PeriodFormat.second=\ second
PeriodFormat.seconds=\ seconds
PeriodFormat.millisecond=\ millisecond
PeriodFormat.milliseconds=\ milliseconds
2.5, , . , , ( ). , . .
: Java 8, , .
2015-08-26:
Time4J-v4.3 ( Maven Central) , 45 :
import static net.time4j.CalendarUnit.*;
import static net.time4j.ClockUnit.*;
IsoUnit[] units = {YEARS, MONTHS, DAYS, HOURS, MINUTES, SECONDS};
PlainTimestamp start = PlainDate.of(2013, 4, 11).atTime(13, 45, 21);
PlainTimestamp end = SystemClock.inLocalView().now();
Duration<?> duration = Duration.in(units).between(start, end);
String s = PrettyTime.of(Locale.US).print(duration, TextWidth.WIDE);
System.out.println(s);
Time4J ?
- , .
- 45 .
- , , , , .
- ( , "" )
- 3 : WIDE, ABBREVIATED (SHORT) NARROW
- Java-8 , Java-8-,
java.time.Period java.time.Duration, Time4J.