package com.liu.Utils;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import org.aspectj.apache.bcel.generic.ReturnaddressType;

public class DateUtil {
	/**  
	* @Title: formatDate  
	* @Description:格式化日期
	*/  
	public static String formatDate(Date date,String format){ //Date型格式化字符串
		String result="";
		SimpleDateFormat sdf=new SimpleDateFormat(format);
		if(date!=null)
		{
		result=sdf.format(date);
		}
		return result;
	}
	public static String formatString(String str)throws Exception//SqlDate通过字符串进行格式化
	{
		if(str==null){
			return null;
		}
		SimpleDateFormat sdf1= new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH);
		SimpleDateFormat sdf2= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

		return sdf2.format(sdf1.parse(str));
	}
	public static String formatString1(String str)throws Exception
	{
		if(str==null){
			return null;
		}
		SimpleDateFormat sdf1=new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy",Locale.ENGLISH);
		SimpleDateFormat sdf2=new SimpleDateFormat("MM-dd");
		return sdf2.format(sdf1.parse(str));
	}
	public static String formatString2(String str)throws Exception
	{
		if(str==null){
			return null;
		}
		SimpleDateFormat sdf1=new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy",Locale.ENGLISH);
		SimpleDateFormat sdf2=new SimpleDateFormat("yyyy-MM-dd");
		return sdf2.format(sdf1.parse(str));
	}
	public static String formatString3(String str)throws Exception
	{
		if(str==null){
			return null;
		}
		SimpleDateFormat sdf1=new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy",Locale.ENGLISH);
		SimpleDateFormat sdf2=new SimpleDateFormat("yyyy");
		return sdf2.format(sdf1.parse(str));
	}
	public static String getCurrentDateStr()throws Exception{ //格式化当前日期
		Date date=new Date();

		SimpleDateFormat sdf=new SimpleDateFormat("yyyMMddhhmmss");
		return sdf.format(date);
		
	}

	
}
最近下载更多
xiaopengzep  LV1 3月24日
问耳朵  LV2 2023年12月14日
海棠花瘦  LV9 2023年6月12日
yangbulx  LV3 2023年6月7日
微信网友_6495054193971200  LV2 2023年5月28日
邬松桥  LV11 2022年11月16日
LJLljl002  LV5 2022年9月18日
yymmdm  LV6 2022年8月10日
wppppp  LV3 2022年4月23日
微信网友_5916966536499200  LV2 2022年4月15日
最近浏览更多
xiaopengzep  LV1 3月24日
zhanxy  LV2 3月11日
minjing123  LV8 1月4日
lilong007  LV20 2023年12月30日
WBelong  LV7 2023年12月27日
问耳朵  LV2 2023年12月14日
空中飞尘  LV13 2023年12月13日
shuangfu  LV24 2023年12月2日
limenghaoqwer  LV2 2023年11月27日
abandan  LV4 2023年11月6日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友