List of usage examples for org.joda.time DateTimeConstants SECONDS_PER_MINUTE
int SECONDS_PER_MINUTE
To view the source code for org.joda.time DateTimeConstants SECONDS_PER_MINUTE.
Click Source Link
From source file:rcrr.reversi.Clock.java
License:Open Source License
/** * Returns a String representing the clock. * The format is mm:ss corresponding to the given time in milliseconds, where: * - mm is the amount of minutes/*from www . ja v a 2 s . c o m*/ * - ss is the amount of seconds * * @param duration time in milliseconds * @return a formatted {@code String} with minutes and seconds */ private static String timeString(final Duration duration) { final long durationAsMilliseconds = duration.getMillis(); final long durationAsSeconds = durationAsMilliseconds / DateTimeConstants.MILLIS_PER_SECOND; final long minutes = durationAsSeconds / DateTimeConstants.SECONDS_PER_MINUTE; final long seconds = durationAsSeconds - (minutes * DateTimeConstants.SECONDS_PER_MINUTE); return TIME_FORMATTER.format(minutes) + ":" + TIME_FORMATTER.format(seconds); }
From source file:uk.ac.susx.tag.method51.core.params.codec.concrete.DurationCodec.java
License:Apache License
@Override public Duration decodeString(String value) throws DecodeException { Duration result = null;/*w w w. j a va 2 s . c om*/ long milliseconds; try { milliseconds = Long.parseLong(value); } catch (NumberFormatException e) { try { if (value.length() == 0) { throw new IllegalArgumentException("zero length interval specification"); } value = value.toUpperCase(); if (!value.matches(".*[DWMHS].*")) { throw new IllegalArgumentException( "no time units specified, see ISO 8601 duration specification (months / years not supported): http://en.wikipedia.org/wiki/ISO_8601#Durations"); } if (!value.startsWith("P")) { value = "P" + value; } Matcher m = Pattern.compile("[HMS]").matcher(value); if (!value.contains("T") && m.find()) { String c = m.group(0); int i = value.indexOf(c); value = value.substring(0, i - 1) + "T" + value.substring(i - 1); } Period period = ISOPeriodFormat.standard().parsePeriod(value); long seconds = 0; seconds += period.getSeconds(); seconds += period.getMinutes() * DateTimeConstants.SECONDS_PER_MINUTE; seconds += period.getHours() * DateTimeConstants.SECONDS_PER_HOUR; seconds += period.getDays() * DateTimeConstants.SECONDS_PER_DAY; seconds += period.getWeeks() * DateTimeConstants.SECONDS_PER_WEEK; milliseconds = seconds * 1000; } catch (IllegalArgumentException e1) { throw new DecodeException("'" + value + "' is not a number, or an ISO 8601 duration", e1); } } result = new Duration(milliseconds); return result; }