All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hframework.common.springext.converter.DateConverter Maven / Gradle / Ivy

There is a newer version: 1.0.2
Show newest version
package com.hframework.common.springext.converter;

import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by zhangquanhong on 2016/6/23.
 */
public class DateConverter implements Converter {
    private String format = "yyyy-MM-dd HH:mm:ss";

    public DateConverter() {
        this.format = format;
    }
    public DateConverter(String format) {
        this.format = format;
    }

    public Date convert(String source) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
        dateFormat.setLenient(false);
        try {
            return dateFormat.parse(source);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy