android - Remove milliseconds and seconds from Joda time output -
i trying output time remaining date (15th of august in madrid, spain) , code can textview display correctly. however, displays milliseconds , seconds remove, , "months" convert days.
could give me hand?
datetimezone timezone = datetimezone.forid("europe/madrid"); datetime target = new datetime(2015, 8, 15, 0, 0, 0, timezone); datetime = new datetime(timezone); period period = new period(now, target); periodformatter formatter = periodformat.getdefault(); string output = formatter.print(period); textview tv = (textview) v.findviewbyid(r.id.tv); tv.settext(output);
a pure joda solution looks like:
datetimezone timezone = datetimezone.forid("europe/madrid"); datetime target = new datetime(2015, 8, 15, 0, 0, 0, timezone); datetime = new datetime(timezone); period period = new period(now, target); periodformatter formatter = periodformat.getdefault(); string output = formatter.print(period); system.out.println(output); // 4 weeks, 2 days, 17 hours, 2 minutes, 10 seconds , 817 milliseconds period = new period( now, target, periodtype.daytime().withsecondsremoved().withmillisremoved()); output = formatter.print(period); system.out.println(output); // 30 days , 17 hours
the decisive change using specialized variation of periodtype.
as long want full english words (using periodformat.getdefault()
) joda-time fine (there built-in support 9 languages - other libs have better i18n-features). otherwise, duration handling , formatting not offered @ standard java other wrong answer of @vv pretends.
Comments
Post a Comment