简体   繁体   中英

How to get minutes from Joda-Time that is not formatted

I have the following:

DateTime startDate = session.getProgramSessionDetail().getStartDate();
DateTime endDate = session.getProgramSessionDetail().getEndDate();
Minutes minutes = Minutes.minutesBetween(startDate, endDate);

String testing = minutes.toString();

logger.debug("Minutes :: " + testing);

The output is:

Minutes :: PT90M

I want the output to be just 90 so I can convert to int and use in some other fields.

I could parse it out but is there not a way to just get the plain numerical value.

The Minutes::toString() method returns the minutes value as a ISO8601 duration . In this case, PT90M means "a duration of 90 minutes".

To get just the minutes value, you can use the getMinutes() method , that returns the value as int , so you can print it like this:

int value = minutes.getMinutes();
logger.debug("Minutes :: " + value);

The output will be:

Minutes :: 90

As this method already returns an int , you don't need to convert it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM