Example usage for java.text SimpleDateFormat toString

List of usage examples for java.text SimpleDateFormat toString

Introduction

In this page you can find the example usage for java.text SimpleDateFormat toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:com.xpn.xwiki.objects.classes.DateClass.java

@Override
public BaseProperty newPropertyfromXML(Element ppcel) {
    String value = ppcel.getText();
    BaseProperty property = newProperty();

    if (StringUtils.isEmpty(value)) {
        return property;
    }//from  www  .  j  av a  2s.  c o  m

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
    try {
        property.setValue(sdf.parse(value));
    } catch (ParseException e) {
        SimpleDateFormat sdf2 = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy", Locale.US);
        try {
            if (LOG.isWarnEnabled()) {
                LOG.warn("Failed to parse date [" + value + "] using format [" + sdf.toString()
                        + "]. Trying again with format [" + sdf2.toString() + "]");
            }
            property.setValue(sdf2.parse(value));
        } catch (ParseException e2) {
            if (LOG.isWarnEnabled()) {
                LOG.warn("Failed to parse date [" + value + "] using format [" + sdf2.toString()
                        + "]. Defaulting to the current date.");
            }
            property.setValue(new Date());
        }
    }
    return property;
}