periodformatter

Displaying “negative” time periods with Joda-Time PeriodFormatter

对着背影说爱祢 提交于 2020-01-14 17:16:51
问题 I'm using joda-time (1.6.2) on a project and one of the things I'm doing is getting the difference between a predicted time and an actual time. Sometimes this difference is positive, sometimes negative. While the appropriate approach may be to use a Duration rather than a Period , using a PeriodFormatter to display the result led me a question about the PeriodFormatterBuilder class. As an example: DateTime d1 = new DateTime(2011, 6, 17, 13, 13, 5, 0) ; DateTime d2 = new DateTime(2011, 6, 17,

Understanding joda time PeriodFormatter

寵の児 提交于 2019-12-23 15:29:03
问题 I thought I understand it, but apparently I don't. Can you help me make these unit tests pass? @Test public void second() { assertEquals("00:00:01", OurDateTimeFormatter.format(1000)); } @Test public void minute() { assertEquals("00:01:00", OurDateTimeFormatter.format(1000 * 60)); } @Test public void hour() { assertEquals("01:00:00", OurDateTimeFormatter.format(1000 * 60 * 60)); } @Test public void almostMidnight() { final int secondsInDay = 60 * 60 * 24; assertEquals("23:59:59",

PeriodFormatter not showing days

柔情痞子 提交于 2019-12-07 03:54:03
问题 I am using a PeriodFormatter to return a string showing the time until an event. The code below keeps creating strings like 1146 hours 39 minutes instead of x days y hours z minutes. Any ideas? Thanks, Nathan PeriodFormatter formatter = new PeriodFormatterBuilder() .printZeroNever() .appendDays() .appendSuffix( "d " ) .appendHours() .appendSuffix( "h " ) .appendMinutes() .appendSuffix( "m " ) .toFormatter(); return formatter.print( duration.toPeriod() ); 回答1: This is because you convert

PeriodFormatter not showing days

☆樱花仙子☆ 提交于 2019-12-05 06:14:24
I am using a PeriodFormatter to return a string showing the time until an event. The code below keeps creating strings like 1146 hours 39 minutes instead of x days y hours z minutes. Any ideas? Thanks, Nathan PeriodFormatter formatter = new PeriodFormatterBuilder() .printZeroNever() .appendDays() .appendSuffix( "d " ) .appendHours() .appendSuffix( "h " ) .appendMinutes() .appendSuffix( "m " ) .toFormatter(); return formatter.print( duration.toPeriod() ); This is because you convert Duration to Period with method Duratoin::toPeriod This is described in Joda-time documentation: public Period