Package org.rythmengine.extension

Source Code of org.rythmengine.extension.JodaDateTimeFormatter

package org.rythmengine.extension;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.util.Locale;

/**
* Created by luog on 2/01/14.
*/
public class JodaDateTimeFormatter implements IFormatter {
    @Override
    public String format(Object val, String pattern, Locale locale, String timezone) {
        if (!(val instanceof DateTime)) return null;
        DateTimeFormatter fmt;
        if (null != pattern) fmt = DateTimeFormat.forPattern(pattern);
        else fmt = DateTimeFormat.fullDateTime();

        fmt = fmt.withLocale(locale);
        if (null != timezone) {
            DateTimeZone dtz = DateTimeZone.forID(timezone);
            fmt = fmt.withZone(dtz);
        }
        return fmt.print((DateTime)val);
    }
}
TOP

Related Classes of org.rythmengine.extension.JodaDateTimeFormatter

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.