Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
package is.rebbi.core.formatters;
import java.text.FieldPosition;
import java.text.Format;
import java.text.ParsePosition;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.util.Objects;
public class DateTimeFormatterWrapper extends Format {
private DateTimeFormatter _formatter;
public DateTimeFormatterWrapper( DateTimeFormatter formatter ) {
Objects.requireNonNull( formatter );
_formatter = formatter;
public StringBuffer format( Object object, StringBuffer toAppendTo, FieldPosition pos ) {
if( object == null ) {
return toAppendTo;
return toAppendTo.append( _formatter.format( (TemporalAccessor)object ) );
public Object parseObject( String source, ParsePosition pos ) {
return _formatter.parse( source, pos );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment