DateUtil

package Utils;

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

public class DateUtil {
	private static final String PATTERN ="yyyy-MM-dd";
	private DateUtil() {}
	public static String dateToString(Date date, String pattern){
		SimpleDateFormat sd = createSimpleDate(pattern);
		sd.applyPattern(pattern);
		String res = sd.format(date);
		return res;
	}
	public static String dateToString(Date date){
		return dateToString(date,"");
		
	}
	
	public static Date toDate(String str, String pattern){
		SimpleDateFormat sd = createSimpleDate(pattern);
		Date date = null;
		try {
			date = sd.parse(str);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return date;
	}
	public static SimpleDateFormat createSimpleDate(String pattern){
		if(StringUtils.isBlank(pattern)){
			pattern = PATTERN;
		}
		SimpleDateFormat sd = new SimpleDateFormat();
		sd.applyPattern(pattern);
		return sd;
	}
}
package Utils;
public class StringUtils {
	private StringUtils() {}
	public static boolean hasLength(String str){
		return str != null && !"".equals(str.trim());
	}
	
	public static boolean isBlank(String str) {
		return !hasLength(str);
	}
}

 

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ChasenZh/article/details/81592360
个人分类: java
上一篇各种排序方式
想对作者说点什么? 我来说一句
相关热词

没有更多推荐了,返回首页

关闭
关闭
关闭