editors.DateTimeEditor.java Source code

Java tutorial

Introduction

Here is the source code for editors.DateTimeEditor.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package editors;

import java.beans.PropertyEditorSupport;
import org.joda.time.DateTime;

/**
 *
 * @author jzelezny
 */
public class DateTimeEditor extends PropertyEditorSupport {

    public static final String DATE_FORMAT = "MM/dd/yyyy";

    @Override
    public void setAsText(String text) {
        DateTime dateTime = DateTime.parse(text);
        setValue(dateTime);
    }

    @Override
    public String getAsText() {
        DateTime dateTime = (DateTime) getValue();
        if (dateTime == null) {
            return null;
        } else {
            return dateTime.toString(DATE_FORMAT);
        }
    }

}