import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class DateUtil {
public static String getTimeStr(Date date){
String str=null;
DateFormat df=null;
df=DateFormat.getTimeInstance();
str=df.format(date);
return str;
}
public static String getDateTimeStr(Date date){
String str=null;
DateFormat df=DateFormat.getDateTimeInstance();
str=df.format(date);
return str;
}
public static String getCNDateStr(Date date){
String str=null;
DateFormat df=DateFormat.getDateInstance(DateFormat.FULL, Locale.CHINA);
str=df.format(date);
return str;
}
public static String getCnTimeStr(Date date){
String str=null;
DateFormat df=DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL,Locale.CHINA);
str=df.format(date);
return str;
}
public static String getDateTimeStrByFormat(Date date){
String str=null;
SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日 HH点mm分ss秒");
str=sdf.format(date);
return str;
}
public static Date getDate(String str){
Date date=null;
DateFormat df=DateFormat.getDateInstance();
try {
date=df.parse(str);
} catch (ParseException e) {
e.printStackTrace();
System.out.println("@@格式化日期异常@@");
}
return date;
}
public static Date getDateByFormat(String str){
Date date=null;
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
date=sdf.parse(str);
} catch (ParseException e) {
e.printStackTrace();
System.out.println("@@获取自定义格式日期异常@@");
}
return date;
}
}