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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -