您可能需要针对自己的格式进行一些调整,但可以尝试以下方法:
PeriodFormatter formatter = new PeriodFormatterBuilder() .appendDays().appendSuffix("d ") .appendHours().appendSuffix("h ") .appendMinutes().appendSuffix("min") .toFormatter();Period p = formatter.parsePeriod("2d 5h 30min");请注意,如果需要使参数更灵活
appendSuffix,可以使用带
variants参数的参数。
更新 :Joda Time已添加
Period.toStandardDuration(),并且您可以从那里
getStandardSeconds()以秒为单位获取经过时间
long。
如果您使用的是没有这些方法的旧版本,则仍可以通过假设一天中的标准24 / hr,60min /
hr等来自己计算时间戳。(在这种情况下,请利用
DateTimeConstants该类中的常量来避免需要魔术数字。)



