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

com.yishuifengxiao.common.tool.format.LocalDateFormatter Maven / Gradle / Ivy

Go to download

本工具包主要集成了目前在项目开发过程中个人经常会使用到的一些工具类,对工具类进行了一下简单的封装

There is a newer version: 8.0.0
Show newest version
package com.yishuifengxiao.common.tool.format;

import java.text.ParseException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

import org.springframework.format.Formatter;

/**
 * 字符串与LocalDate转化类
 * 
 * @author yishui
 * @date 2018年7月26日
 * @Version 0.0.1
 */
public class LocalDateFormatter implements Formatter {
	private DateTimeFormatter formatter;
	private String datePattern;

	public LocalDateFormatter(String datePattern) {
		this.datePattern = datePattern;
		formatter = DateTimeFormatter.ofPattern(datePattern);
	}

	@Override
	public LocalDate parse(String s, Locale locale) throws ParseException {
		try {
			return LocalDate.parse(s, DateTimeFormatter.ofPattern(datePattern));
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
	}

	@Override
	public String print(LocalDate localDate, Locale locale) {
		return localDate.format(formatter);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy