Package com.rupertjones.globalcron.util

Source Code of com.rupertjones.globalcron.util.JodaTimeFormatter

package com.rupertjones.globalcron.util;

import org.joda.time.DateTime;
import org.joda.time.Period;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.PeriodFormatter;
import org.joda.time.format.PeriodFormatterBuilder;

/**
* <p>&copy Rupert Jones 2011,2012</p>
*
* @author rup
*/
public class JodaTimeFormatter {
    public static String format(Period period) {
        PeriodFormatter output = new PeriodFormatterBuilder()
                .appendDays()
                .appendSuffix(" day", " days")
                .appendSeparator(", ")
                .appendHours()
                .appendSuffix(" hour", " hours")
                .appendSeparator(", ")
                .appendMinutes()
                .appendSuffix(" minute", " minutes")
                .appendSeparator(", ")
                .appendSeconds()
                .appendSuffix(" second", " seconds")
                .toFormatter();
        return output.print(period);
    }

    /**
     * Print out the given time with the given format
     * @param format, eg "EEE dd MMM yyyy HH:mm:ss"
     * @param when, the moment of time to display
     * @return formatted version of the given date.
     */
    public static String format(String format, DateTime when) {
        return DateTimeFormat.forPattern(format).print(when);
    }
}
TOP

Related Classes of com.rupertjones.globalcron.util.JodaTimeFormatter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.